Showing posts with label struts. Show all posts
Showing posts with label struts. Show all posts

March 05, 2014

Latest Interview Questions on JAVA (Prepared by Sumitav Tripathy)

Wipro Interview Questions (Face to Face 1st March 2014)   For 4+ Experience.

·         Difference between Abstract Class & Interface?
·         Difference between Array List & Vector?
·         Difference between Array List & Linked List?
·         What is the script let in JSP can you write a script let for me.
·         For generating Excel from JSP what you do. I told Jasper Reports.
·         Explain the flow of Struts framework & how your project works on that.
·         What is MVC?
·          What is dependency injection?  How many types?
·         He asked about Spring AOP I told I do not know.
·         What is hibernate what are the advantages over JDBC?
·          How do you debug your Web Application?
·         What are the types of Loggers (specific to Log4J)
·         Which collection had you used in your project to access data from database I told HashMap
·         What is difference between HashMap & Hashtable?
·         Difference between Comparable & Comparator?
·         What is Marker Interface?
·         Difference between final, finally & finalize.
·         Difference between yield, join & sleep methods.
·         Why Strings are final. Why Strings are Immutable
·         What is difference between load & get java.
·         Difference between get & post.
·         What is difference between sendRedirect & forward?
·         JSP Lifecycle. Servlet life cycle. At which phase of JSP Lifecycle JSP converts to Servlet.
·         Do you know CSS & HTML.I told I know only basics?


IBS Interview Questions (Face to Face 27th Feb 2014):   For 4+ Experience
·         Difference between Array List & Vector.
·         Explain Spring Web MVC Flow
·         Difference between Abstract Class & Interface.
·         Difference between Array List & Linked List.
·         Write a program which will use all the same functions of ArrayList by using array like insertion, deletion without using any collection methods. Means create an ArrayList using array.
·         How many ways can you create Threads?
·         Tell me real time scenarios when to extend Thread class & when to implement runnable interface.
Which one is better?  In which scenario you will prefer extending Thread class to implement runnable interface.
 They asked about some exception in Multithreading which I had never heard.
·          There is a class which has 2 variables Employee name (String) & Employee Id(number ).
·         (a)Write a program (Here after read WAP as short form of  “Write a program”)  by using collection framework to sort according to the increasing order of employee Id. Which collection will you use  ?
·         (b) WAP by using collection framework to sort according to the alphabetical or
der of employee name. Which collection will you use?
·          How HashMap works?
·          Difference between yield, join & sleep methods.
·         What do you understand by immutability?
·         String  s=”Sumitav”; String  s1=new String (“Sumitav”);
·         s==s1    True/False ?   Also s.equals(s1);  what will be the output ?
·         Are only strings Immutable? I told no wrapper classes too.
I am writing a variable in an interface by default what will be its modifiers & access types I told “public static final” then they asked if one method is declared what will be the access specified. I told default write answer is public.
·         Can we write a constructor inside an Interface?  I told No
·         Then they asked can we write a constructor inside abstract class. I told yes then they asked what will be the purpose of this constructor if we cannot create object. I told for child class it will be used by super(); 
abstract class A {
     A(){ }
     abstract add();
}

Class B extends A {
A(){ }
add(){
sop("...");
}
}

·         Can you override the above constructor in child class? I was not sure.
·         Can an interface have a concrete method? I told no. Abstract class can have but not an interface.
·         What is second level cache in hibernate?
·         How you do Spring-Hibernate Integration.
·         Difference between default & private.


CapGemini Telephonic Interview Questions on 2nd March 2014:  For 4+ Experience.


·         What is Polymorphism what is the purpose.
·         What is Encapsulation? What is the purpose?
·         Flow of Struts according to your project.
·         Difference between Comparable & Comparator?
·          Difference between Hashtable & HashMap?
·         What is difference between sendRedirect & forward?
·         What is request Dispatcher?
·         Explain JSP Lifecycle.


Accenture Telephonic Interview  Questions on 10th March 2014:  For 4+ Experience

·         Can you tell me the life cycle of a servlet?
·         What is the difference between a servlet & JSP?
·         Can you tell me the difference between doGet & doPost. I told get passes data as query string so not safe.
·         Does get is faster than post?  I told I am not sure.
·         What is difference between JDK & JRE?
·         How you track a session & in how many ways can you track a session.  I answered cookies, URL rewriting & session.
·         You have a list you want to remove duplicates in the list. How will you do that ?  I told we have to use Set because set does not allow duplication. He told that’s what I was expecting.
·         How you compare a list of objects. I told comparable & comparator we have & the difference between them.
·         Have you worked on front end? I told yes then the interviewer asked how you do “pagination” in webpage. I asked pardon!!!! Question bounced J He asked do you understand what is pagination?  When you search in Google you search something at the bottom of the page you find 1, 2, 3…. That is called pagination. How will you do that? I told I think there may be some directives like JSP page directives. Just bluffed J I could not answer might be href of splitting table. How will you develop pagination in your application?
·         How will you debug a JavaScript .Suppose you have developed a Web application, you have used some JavaScript to validate your application right!!! Now you want to debug that web application, you have written one JavaScript function but in that JavaScript function something is going wrong. Now you have to identify the problem how will you identify?  I could not tell what I told was breakpoint, Starting server in debug mode then F5, F6, F7 etc. He told you are telling Java. I am asking how to debug JavaScript. You have written a function it should return either true/false how will you find out it is returning correctly true/false?
·         In JavaScript you have written an equation that equation is running but you don’t know that equation is returning correct value or not how will you identify that.
·         Have you worked on any JavaScript libraries? Like JQuery, DOJO? I told No.
·         Do you know what AJAX is? I told yes AJAX is advancement over JavaScript we use it for auto refreshing of web pages but I have not used.
·         How request processor is done in Struts.
·         How will it go to Action servlet?
·         In web.xml what will you define?
·         To deploy struts what will you write in web.xml?
·         Can you tell me which part of the Action class the business logic will be?
·         Can you tell me the definition of the execute ()? Syntax of execute () what are the signature, return type, input parameters, if it throws exception what exception type it throws?
·         Can you give the structure of Struts-config action tag? What will be inside? What is type generally?
·         How will you validate a form bean?
·         Have you worked in Tiles?
·         Can you describe validate & reset methods?
·         What will validate () returns?
·         Difference between Struts & Spring? What are the differences in the flow of both Struts & Spring?
·         Can you tell the difference get & load method in hibernate?
·         What is the difference between Sorted & ordered Collection in Hibernate?
·         What is lazy loading in hibernate? How it is achieved in Hibernate?
·         What is hibernate session & session factory?
·         Can we have multiple hbm files in Hibernate? How will you manage?
·         Difference between is session object & session lock?
·         Difference between ArrayList & Vector?
·         What is Serialization?
·         Why we need Serialization?
·         Why we use properties file?
·         Can we create objects without using new operator?
·         I have an object & I want to find out is it a String or Integer how can we find out?
String currentObject=12;
Object obj = (Object) currentObject;
If(obj instanceOf Integer){ String.out.println(“this Object is integer.”);
}else if(obj instanceOf String){ String.out.println(“this Object is String.”);
}
·         What are the types of polymorphism Java Supports?


These questions were faced by my friend Sumitav Tripathy (sumitav4job@gmail.com) & contributed to MYJAVACAFE after becoming successful.
Read more ...

July 05, 2012

What are the diferences between struts and spring frameworks:


Difference between struts and springs could be analysed from various facets.

(1) Purpose of each framework.
(2) Various feature offerings at framework level.
(3) The design & stuff.

Firstly, Struts is a sophisticated framework offering the easy 2 develop, structured view/presentation layer of the MVC applications. Advanced, robust and scalable view framework underpinning reuse and seperation of concerns to certain extent. Springs is a Lightweight Inversion of Control and Aspect Oriented Container Framework. Every work in the last sentence carry the true purpose of the Spring framework. It is just not a framework to integrate / plug in at the presentation layer. It is much more to that. It is adaptible and easy to run light weight applications, it provides a framework to integrate OR mapping, JDBC etc., Infact Struts can be used as the presentation tier in Spring.

Secondly, Springs features strictly associate with presentation stuff. It offers Tiles to bring in reuse at presentation level. It offers Modules allowing the application presentation to segregate into various modules giving more modularity there by allowing each module to have its own Custom/Default Request Processor. Spring provides Aspect Oriented programming, it also solves the seperation of concerns at a much bigger level. It allows the programmer to add the features (transactions, security, database connectivity components, logging components) etc., at the declaration level. Spring framework takes the responsibility of supplying the input parameters required for the method contracts at runtime reducing the coupling between various modules by a method called dependency injection / Inversion of Control.

Thirdly, Struts is developed with a Front Controller and dispatcher pattern. Where in all the requests go to the ActionServlet thereby routed to the module specific Request Processor which then loads the associated Form Beans, perform validations and then handovers the control to the appropriate Action class with the help of the action mapping specified in Struts-config.xml file. On the other hand, spring does not route the request in a specific way like this, rather it allows to you to design in your own way however in allowing to exploit the power of framework, it allows you to use the Aspect Oriented Programming and Inversion of Control in a great way with great deal of declarative programming with the XML. Commons framework can be integrated to leverage the validation in spring framework too. Morethan this, it provides all features like JDBC connectivity, OR Mapping etc., just to develop & run your applications on the top of this.


Differences Briefly :

1)Struts is a web framework while Spring is not.

2)Spring is a Layered Architecture while Struts is not.

3)Struts is heavy weight while Spring is light weight.

4)Struts supports tag Library while Spring does not.

5)Spring is loosely coupled while Struts is tightly coupled.

6)Spring provides easy integration with ORM technologies while in struts, we need to do coding manually.

7)Struts easily integrate with other client side technologies. It is not easy in case of spring.

Read more ...

June 29, 2012

Setting Up Eclipse with Java 1.6 on Windows


Step 1 - Download Java
Step 2 - Install Java
Step 3 - Set the PATH
Step 4 - Set the CLASSPATH
Step 5 - Test the Java installation
Step 6 - Download and install Eclipse
Step 7 - Test the Eclipse installation
Step 1     Download Java 1.6 package for Windows
Click the Download button alongside the label  JDK 6 Update 2 (or similar). On that page, accept the license agreement near the top of the page and download either the online or offline Windows Platform installation file. The offline option is a big file (c. 66MB) which includes all of the Java language and can be used to install even when an internet connection is not available. The online option is a small file (c. 0.4MB) that when run downloads Java over an internet connection as installation proceeds. It is recommended that you save the installer file to the Desktop so that it can be found easily. 



Step 2     Install the Java 1.6 package.
a. Double-click the file that you just downloaded. The name should be something similar to jdk-6u2-windows-i586-p.exe or, if you chose the online installation option,jdk-6u2-windows-i586-p-iftw.exe

b. Accept the License Agreement.

c. Accept all the default choices. In other words, just keep clicking "Next".

d. Wait for the installation to complete.



Step 3     Update the PATH environment variable.
(The following is adapted from Sun's Installation Notes for JDK 1.6 Microsoft Windows)

You can run the JDK without setting the PATH variable, or you can optionally set it as a convenience. To save yourself a lot of careful typing, it is highly recommended that you set the path variable.
Set the PATH variable if you want to be able to conveniently run the JDK executables (javac.exejava.exejavadoc.exe, etc.) from any directory without having to type the full path of the command. If you don't set the PATH variable, you need to specify the full path to the executable every time you run it, such as:
   C:> "\Program Files\Java\jdk1.6.0_\bin\javac" MyClass.java

It's useful to set the PATH permanently so it will persist after rebooting.
To set the PATH permanently, add the full path of the jdk1.6.0_\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_\bin, where  is a two-digit number. Set the PATH as follows, according to whether you are on Microsoft Windows NT, XP, 98, 2000, or ME.
Microsoft Windows NT, 2000, and XP - To set the PATH permanently:
  1. Choose Start, Settings, Control Panel, and double-click System. On Microsoft Windows NT, select the Environment tab; on Microsoft Windows XP and 2000 select the Advanced tab and then Environment Variables. Look for "Path" in the User Variables and System Variables. If you're not sure where to add the path, add it to the right end of the "Path" in the User Variables. A typical value for PATH is:
       C:\Program Files\Java\jdk1.6.0_\bin 
    Where is the latest version number. For example, if you downloaded jdk1.6.0_02, then the value to add to the path is:
       C:\Program Files\Java\jdk1.6.0_02\bin 
                                                                                              Capitalization doesn't matter. Click "Set", "OK" or "Apply".The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should only have one bin directory for a JDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to jdk1.6.0_\bin.
  2. The new path takes effect in each new Command Prompt window you open after setting the PATH variable.
Microsoft Windows 98 - To set the PATH permanently, open the AUTOEXEC.BAT file and add or change the PATH statement as follows:
  1. Start the system editor. Choose "Start", "Run" and enter sysedit, then click OK. The system editor starts up with several windows showing. Go to the window that is displaying AUTOEXEC.BAT
  2. Look for the PATH statement. (If you don't have one, add one.) If you're not sure where to add the path, add it to the right end of the PATH. For example, in the following PATH statement, we have added the bin directory at the right end:
       PATH C:\WINDOWS;C:\WINDOWS\COMMAND;"C:\PROGRAM FILES\JAVA\JDK1.6.0_\BIN" 
    Capitalization doesn't matter. The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows searches for programs in the PATH directories in order, from left to right. You should only have one bin directory for a JDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to jdk1.6.0_.
  3. To make the path take effect in the current Command Prompt window, execute the following:
       C:> c:\autoexec.bat
    
        
    To find out the current value of your PATH, to see if it took effect, at the command prompt, type:
       C:> path
    
        
Microsoft Windows ME - To set the PATH permanently:
From the start menu, choose programs, accessories, system tools, and system information. This brings up a window titled "Microsoft Help and Support". From here, choose the tools menu, then select the system configuration utility. Click the environment tab, select PATH and press the edit button. Now add the JDK to your path as described in step b above. After you've added the location of the JDK to your PATH, save the changes and reboot your machine when prompted.



Step 4     Set the CLASSPATH environment variable.
The CLASSPATH variable tells Java where to look for *.class bytecode files. Bytecode is created when you compile your *.java files. Set the CLASSPATH as follows, according to whether you are on Microsoft Windows NT, XP, 98, 2000, or ME.
Microsoft Windows NT, 2000, and XP - To set the CLASSPATH:
  1. Choose Start, Settings, Control Panel, and double-click System. On Microsoft Windows NT, select the Environment tab; on Microsoft Windows 2000 or XP select the Advanced tab and then Environment Variables. Look for "classpath" in the User Variables and System Variables, then click Edit. If no classpath variable exists, create it by clicking New and adding "classpath" to the User Variables. A typical value for CLASSPATH is:
       .;..
    The '.' represents your current directory, allowing you to compile and run code in your current directory (as shown in the command line of your command window). The '..' represents the folder above the current directory. Together, the '.' and '..' cover most situations where you need to compile and run programs. The semi-colon ';' separates these entries. The CLASSPATH can contain multiple directories separated by semi-colons. 
    Click "Set", "OK" or "Apply".
  2. The new classpath takes effect in each new Command Prompt window you open after setting the CLASSPATH variable. 
Microsoft Windows 98 - To set the CLASSPATH permanently, open the AUTOEXEC.BAT file and add or change the CLASSPATH statement as follows:
  1. Start the system editor. Choose "Start", "Run" and enter sysedit, then click OK. The system editor starts up with several windows showing. Go to the window that is displaying AUTOEXEC.BAT
  2. Look for the CLASSPATH statement. (If you don't have one, add one.) The classpath should contain a '.' and a '..'. If you're not sure where to add them, put them at the right end of the CLASSPATH. For example, in the following CLASSPATH statement, we have added the '.' and '..' directories at the right end:
       CLASSPATH C:\someFolder\someClasses.jar;..;.
    The '.' represents your current directory, allowing you to compile and run code in your current directory (as shown in the command line of your command window). The '..' represents the folder above the current directory. Together, the '.' and '..' cover most situations where you need to compile and run programs. The semi-colon ';' separates these entries. The CLASSPATH can contain multiple directories separated by semi-colons.
  3. To make the classpath take effect in the current Command Prompt window, execute the following:
       C:> c:\autoexec.bat
    To find out the current value of your CLASSPATH, to see if it took effect, at the command prompt, type:
       C:> classpath
        
Microsoft Windows ME - To set the CLASSPATH permanently:
From the start menu, choose programs, accessories, system tools, and system information. This brings up a window titled "Microsoft Help and Support". From here, choose the tools menu, then select the system configuration utility. Click the environment tab, select CLASSPATH and press the edit button. Now add '.' and '..' to your path as described in step b above. Then save the changes and reboot your machine when prompted.


Step 5     Test your Java installation.

a. Open a command window and create a test directory.

    1. Go to Start >> Run... then type cmd and click OK.
    2. Type cd \ and press Enter.
    3. The bottom line should read C:\>
    4. Type mkdir test and press Enter to create a new directory for your testing.
    5. Type cd testand press Enter to enter the directory. The bottom line of the command window should read  C:\test>

      b. Open a text editor and create a small Java program.
      Open WordPad or NotePad (in XP these can be found at Start >> All Programs >> Accessories) and copy in the following simple program:
      public class MyTestApplication {
      
        public static void main(String[] args) {
      
          System.out.println("Hello World!");
        }
      }

      c. Save the program in the test directory. 

      In the text editor menu, choose File >> Save. Then in the File Name field near the bottom of the dialog box, type the following exactly -

         C:\test\MyTestApplication.java
      and click Save.


      d. Confirm the save.
      In your command window, type dir. You should see something similar to -

      C:\test>dir
       Volume in drive C has no label.
       Volume Serial Number is 3C4D-5998

       Directory of C:\test

      29/01/2006  08:20 PM   
                .
      29/01/2006  08:20 PM              ..
      29/01/2006  08:20 PM               129 MyTestApplication.java
                     1 File(s)            129 bytes
                     2 Dir(s)  59,076,812,800 bytes free

      C:\test>


      e. Compile the program.
      Type javac MyTestApplication.java and press Enter. You should see -
      C:\test>javac MyTestApplication.java
      
      C:\test>
      There are two problems that you may encounter at this step.

      Problem 1
      If instead you get the following message -
      C:\test>javac MyTestApplication.java
      'javac' is not recognized as an internal or external command,
      operable program or batch file.
      
      C:\test>
      then Java has not been correctly installed. Perform the following tests :

          1) Check that Java has been correctly downloaded and installed. In particular, look for the directory
      C:\Program Files\Java\jdk1.6.0_\bin. If you cannot find a Java folder in the Program Files folder, then go back to Step 1 now.

          2) Check that the PATH variable has been set correctly. Type echo %path%. You should see something similar to -
      C:\test>echo %path%
      C:\Perl\bin\;c:\programfiles\imagemagick;C:\texmf\miktex\bin;C:\WINDOWS\system32
      ;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI Contr
      ol Panel;C:\Program Files\SecureCRT\;C:\Program Files\Java\jdk1.6.0_02\bin
      
      C:\test>
      If you do not see an entry anywhere in your PATH similar to the one above in bold, then go back to Step 3 now.


      Problem 2
      If instead you get the following message -
      C:\test>javac MyTestApplication.java
      error: cannot read: MyTestApplication.java
      1 error
      
      C:\test>
      then either the CLASSPATH variable is not set or your file is not in the test folder. Perform the following tests:

          1) Check that the CLASSPATH variable has been set correctly. Type echo %classpath%. You should see something similar to -
      C:\test>echo %classpath%
      .;..;C:\someFolder\someClasses.jar
      
      C:\test>
      Note that the classpath may have been automatically updated to contain the location of various class files, and therefore may be longer than the example above. Just make sure that it contains a '.' with a ';' to separate it from other entries. Go back to Step 4 above to edit the classpath.

         2) Make sure you are in the test folder. If you are not, then use the cd command to navigate to the test folder. Once you are in the test folder, type dir at the command line to examine its contents. If you do not see an entry for MyTestApplication.java then Go back to Step 5b above.


      f. Confirm the compilation.
      Type  dir. You should see something similar to -
      C:\test>dir
       Volume in drive C has no label.
       Volume Serial Number is 3C4D-5998
      
       Directory of C:\test
      
      29/01/2006  08:28 PM              .
      29/01/2006  08:28 PM              ..
      29/01/2006  08:28 PM               440 MyTestApplication.class
      29/01/2006  08:20 PM               129 MyTestApplication.java
                     2 File(s)            569 bytes
                     2 Dir(s)  59,076,796,416 bytes free
      
      C:\test>
      If compilation was successful, a *.class file should be present as shown.


      g. Run the program.

      Type java MyTestApplication to run the program. You should see -
      C:\test>java MyTestApplication
      Hello World!
      
      C:\test>
      There is one common problem at this step.

      Problem
      If you get the following message -
      C:\>java MyTestApplication
      Exception in thread "main" java.lang.NoClassDefFoundError: MyTestApplication
      
      C:\>
      then either your class file is not in the test folder (type dir at the command line to make sure), or you are in the wrong directory as in this example, where the javacommand has been typed in C: rather than C:\testGo back to Step 5b above and make sure that you have performed all steps correctly.



      Step 6     
      Download and install Eclipse.
      1. Download Eclipse from the Eclipse downloads page.
      2. Click the link next to "Download now".
      3. If possible, choose a mirror close to your location (e.g. Portland, if you are in Vancouver).
      4. Wait for your download to finish. This may take some time: the installer is a large file (>100MB).
      5. Unzip the downloaded file to C:\Program Files. Again, this may take some time.
      6. In C:\Program Files\eclipse, right-click on eclipse.exe and select Create Shortcut. Rename the shortcut to eclipse and drag it to your Desktop. Then close theeclipse folder.
      7. On the Desktop, double-click on the eclipse shortcut to start the program.
      8. Workspace Launcher dialog will appear. Select "Use this as the default and do not ask again" and click OK.
      9. Eclipse will start up. Either explore the Overview, Tutorials, etc. or close the Welcome page by clicking on the white X to reveal the Java perspective, where you will do your programming.
      Now set up Eclipse to use the latest version of Java for compiling and running your Java programs. 
      (Note: you need to configure Eclipse to use Java 1.6 or it will use an older Java version by default)
      1. Set the default installed JRE to Java 1.6 (this tells Eclipse which libraries to use):
        • Open the Eclipse Preferences Pane (Window -> Preferences) and go to the Java >> Installed JREs subpane.
        • Check the JRE 1.6.0_ as the default (where is a two digit number representing the version number that you downloaded and installed)
        • Click OK to save the settings.
      2. Set the Java compiler to Java 1.6 (this tells Eclipse which compiler to use):
        • In Eclipse Preferences Pane go to Java >> Compiler >> Compliance Level
        • Select "6.0".
        • Click OK to save the settings.
      Eclipse should then be set up properly to compile and run Java 1.6 programs. 


      Step 7     Test the Eclipse installation.

      Create a new Java project with a class and run it.
      1. In the Java Perspective, right-click in Eclipse's Package Explorer window and select New >> Project....
      2. Select Java Project and Next.
      3. Name the project whatever you like (e.g. 'test'). For now the other options do not matter; just click on Finish.
      4. In the Package Explorer window, right-click on the test package and select New >> Class.
      5. Name the class MyTestApplication. For now the other options do not matter; just click on Finish.
      6. Delete everything in the editor that appears. Copy the following into the editor:
      public class MyTestApplication {
      
        public static void main(String[] args) {
      
          System.out.println("Hello World!");
        }
      }
      7.  In the Eclipse menu bar, select File >> Save. If everything is working properly this program should compile automatically without errors.
      8  Run the program by right-clicking on the MyTextApplication class in the package manager, then select Run As >> Java Application.

        "Hello World!" should appear in the console output.
        Read more ...

        February 10, 2012

        Struts Meaning...

        Why we need a controller architecture:
        There are two basic architectures for JavaServer Pages (JSP) development. The first is a page-centric design that allows requests to be made directly to a JSP. The problem with this approach is that it will lead to JSPs with excessive embedded Java code.

        The second, a Model-View-Controller (MVC) architecture variant often called Model 2, is a controller design that uses servlets to handle requests and JSPs to handle presentation. This allows for easy separation of function. Although this is an improvement over the pure JSP model, this design is not without problems. If we code a separate controller servlet for each page, we can end up with dozens of almost identical servlets. If we code a single controller servlet, we end up with a monolithic class with a huge if/else statement that can be difficult to maintain. What's needed to solve this problem is a controller architecture that can handle the repetitive details while still remaining flexible and easy to maintain.

        What is Struts?

        Struts is an open source application framework that provides a flexible and easy to use controller architecture. The nature of the framework helps to promote a Model 2 application architecture with clear separation of functionality. Struts includes a controller servlet, JSP custom tag libraries, and utility classes.

        Struts is being developed as part of the Jakarta project, sponsored by the Apache Software Foundation. Since it is an open source project, it can be downloaded from http://jakarta.apache.org/struts and used for free.

        In this article I will explain the installation of Struts and discuss some of the basic functionality that it provides. For purposes of this discussion, I will be working with Struts installed in Tomcat running on a Win32 platform. To demonstrate some of the functionality of Struts we will code a simple logon function.
        The Struts Architecture

        Struts provides the controller that will serve as the entry point for all requests into our application. The controller determines which Java class will handle a particular request by referring to an XML file that contains mappings of URL paths to Java classes. For a class to be usable by the Struts controller it must extend the Struts Action class. Struts will call the perform( ) method of the Action object passing it the Servlet request and response objects as well as some Struts objects which we will discuss in more detail later.

        In addition, Struts can also be used to run a form pre-processor to do simple form validation. This is controlled through the same XML file. We will also discuss this topic.

        Struts also has custom JSP tag libraries that can simplify JSP programming. Besides special functionality used in Struts programming, custom tags can provide commonly used functionality such as iterating through a collection. Since the Apache Project includes the development of common custom tag libraries, the Struts tag libraries may change in the future
        web.xml File

        There are two XML files that we, as Struts developers, will need to maintain. The first is the web.xml file for our application. This file is stored in the application WEB-INF directory. An example web.xml file is shown in Listing 1.

        The first section of this file identifies the Struts controller class, ActionServlet and provides parameters for this class. The "application" parameter identifies a properties file that contains error messages used by the application. The "config" parameter identifies the Struts configuration file (more on this later).

        The second section of the web.xml file tells Tomcat when to invoked the ActionServlet. In our example, ActionServlet will be invoked whenever a URL ending with ".do" is found. For example, http://127.0.0.1/struts/login.do will invoke the ActionServlet.

        The final section identifies the Struts tag libraries.
        Struts Configuration File

        Listing 2 shows a simple struts-config.xml file that is passed as a parameter to the ActionServlet. It should be placed in the same directory as the web.xml file. The struts-config.xml file can have several sections. The first section we will look at is the section. tells Struts which class to invoke from the ActionServlet. Only the "path" and "type" are required entries. The "type" tells Struts which Action class to invoke when a URL with the model of the "path" is found. From the example in Listing 2, the URL http://127.0.0.1/struts/login.do will cause the ActionServlet to run a method in the class "LoginAction".

        The other tag inside the tag is the tag. This tag gives a way to identify which JSP should be given control by the Action class without coding it inside the class itself.
        Read more ...

        My Favorite Site's List

        #update below script more than 500 posts