You are on page 1of 9

The main difference between servlets and jsp is 1>jsp supports only http protocol.where as servlet supports http,ftp,etc.

, protocols. in servlet java code used heavily, but in jsp we use the simple code it converted to servlet code automatically In Severvelts AutoCompilation is not Possible, means any modification done in the source cdoe of servlet forces the programmer to re compile the servelt , but in JSP any modification in in JSP never forces the programmer to re-compile explicitly. -->JSP is nothing but a servelt internally.So all the benefits of servelt are there in JSP also. These are some another differences .... ----> Servelt Contains pure Java Code, so to develop servelt we require java knowledge; JSP allows HTML Code+ Java Code ( Code in scriptlets), So JSP Page is easy to develop both Java & Non Java programmers. ---->JSP allows tag based programming where as Servelt doesn't. ---->JSP allows implicit Objects , but servelts doesn't ----> Servelt allows programatic Exception Handling (using try catch), JSP supports in-Built Exception HAndling and Declarative Exception Handling ************************************************************************

Difference b/w Servlet & JSP?


servlet acts as controller between application...if submit a form, the values will be gathered by servlet(web.xml) and send to appropriate page as a normal servlets, we simply tell, servlets is a server side components used to develop server side applications... if u make any modification, it will not reflect until u compile the application JSP: this is used for front end applications to design front page, any changes will reflect even without compiling.... The basic differences is that : 1. In servlets, we embedded Java Code in HTML, which is typical and complicated, whereas in JSP we embedded HTML code in Java Code. 2. In servlets, we use the Java Beans or EJB, but in JSP we can't use the concept of EJB. EJB provides the facility of using java compiled classes, which helps in hiding the code. 3. In servlets, if do any change, need to restart the servlet engine, but in case of JSP, no such thing requires. Servlet:-

Servlet is webapplication,that is Request-Response model.Two Package we used in servlet. Generic Http protocol Specific Jsp:- Java server pages used to create dynamic web pages. Basically request coming through the jsp and then forward to generated servlet for processing. A Servlet is a pure Java Class, and compiled to ByteCode, Jsp is embeded into Html Code, before execution, a JSP is must compiled to Servlet code. Normally a JSP is used to dynamically create a User Interface while servlet is used to implement Business Logic, and Data Access Logic. *****************************************************************

Difference between a normal Servlet and Action Servlet ?


one difference b/w both kind of servlet is action servlet implement singleton design pattern. meant there is only one instance of servlet present to serve all the request coming to struts application. Normal servlets creates seprate instance for each incoming request we can say that ActionServlet is a predefiend class of the struts framework under org.apache.struts.Action.ActionServlet. but normal ActionServlet is custum servlet.

Explain about Struts Controller (Action Servlet) ? The main Controller part of the Struts Framework is Action Servlet.

The class org.apache.struts.action.ActionServlet is the heart of the Struts Framework. It is the Controller part of the Struts Framework. ActionServlet is configured as Servlet in the web.xml file as shown in the following code snippets. Code: <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servletclass> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> This Action Servlet is responsible for handing all the request for the Struts Framework, user can map the specific pattern of request to the ActionServlet. <servlet-mapping> tag in the web.xml file specifies the url pattern to be handled by the Servlet. By default it is *.do, but it can be changed to anything. Following code form the web.xml file shows the mapping : Code: <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern>

</servlet-mapping> The above mapping maps all the requests ending with .do to the ActionServlet. ActionServlet uses the configuration defined in struts-config.xml file to decide the destination of the request. What is the difference between Control Of Action Execution Struts 1.x and 2.x ? Struts 1 : Each module in Struts 1 has a separate Request Processors (lifecycles), while all the Actions in the module must share the same lifecycle. Struts 2 : In Struts 2 different lifecycles are created on a per Action basis via Interceptor Stacks. Custom Stacks are created and used with different Actions. ******************** How many types of Action in Struts ? There 5 actions are used in Struts......... 1) ForwardACtion 2) DispatchAction 3) IncludeAction 4) SwitchAction 5) LookupDispatchAction ********************** How Does Struts Work ? Struts is based on the time-proven Model-View-Controller (MVC) design pattern. The MVC pattern is widely recognized as being among the most well-developed and mature design patterns in use. By using the MVC design pattern, processing is broken into three distinct sections aptly named the Model, the View, and the Controller. These are described in the following subsections :

Model Components Model components provide a "model" of the business logic or data behind a Struts program. For example, in a Struts application that manages customer information, it may be appropriate to have a "Customer" Model component that provides program access to information about customers. It's very common for Model components to provide interfaces to databases or back-end systems. For example, if a Struts application needs to access employee information that is kept in an enterprise HR information system, it might be appropriate to design an "Employee" Model component that acts as an interface between the Struts application and the HR information system. Model components are generally standard Java classes. There is no specifically required format for a Model component, so it may be possible to reuse Java code written for other projects. View Components View components are those pieces of an application that present information to users and accept input. In Struts applications, these correspond to Web pages. View components are used to display the information provided by Model components. For example, the "Customer" Model component discussed above would need a View component to display its information. Usually, there will one or more View components for each Web page in a Struts application. View components are generally built using JavaServer Page (JSP) files. Struts provides a large number of "JSP Custom Tags" (sometimes referred to as Struts Tags) which extend the normal

capabilities of JSP and simplify the development of View components. Controller Components Controller components coordinate activities in the application. This may mean taking data from the user and updating a database through a Model component, or it may mean detecting an error condition with a back-end system and directing the user through special error processing. Controller components accept data from the users, decide which Model components need to be updated, and then decide which View component needs to be called to display the results. One of the major contributions of Controller components is that they allow the developer to remove much of the error handling logic from the JSP pages in their application. (After all, if errors in processing occur, the Controller component forwards to an errorprocessing View component, not the primary results View component.) This can significantly simplify the logic in the pages and make them easier to develop and maintain. Controller components in Struts are Java classes and must be built using specific rules. They are usually referred to as Action classes. Explain about General Flow in Struts Frame work ? General Flow : In the MVC Design Pattern, the application flow is mediated by a central Controller. The Controller delegates requests in our case, HTTP requests to an appropriate Handler. A Handler is nothing more than the set of logic that is used to process the request. In the Struts Framework, the Handlers are also called Actions. The Handlers are tied to a Model, and each Handler acts as an adapter, or bridge, between the request and the Model. A Handler or Action

typically uses one or more JavaBeans or EJBs to perform the actual Business logic. The Action gets any information out of the request necessary to perform the desired Business logic and then passes it along to the JavaBean or EJB. The Model represents, or encapsulates, an applications Business logic or state. Control is then usually forwarded back through the Controller. The Controller then dispatches to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a Database or Configuration file. This provides a loose coupling between the View and Model that can make an application significantly easier to create and maintain. While implementing an entire MVC Architecture from scratch isn't all that simple, there are a number of reasons to do it. One reason is to ensure a clean separation between application layers at each tier. Sometimes it seems like overkill to implement additional objects, like ValueObjects, to pass information between layers, but in the long run it is worthwhile. Having a clean separation also makes it easier for development teams to divvy up roles and responsibilities in code, not to mention that you will find your application is much easier to maintain because as changes arise, and they always do, they will be easier to isolate without having to redo objects. Thats the theory anyway, and if you stick to your guns, the theory can be put into good practice. Explain about Token feature in Struts ? Use the Action Token methods to prevent duplicate submits. There are methods built into the Struts action to generate one-use Tokens. A Token is placed in the Session when a form is populated and also into the HTML form as a hidden property. When the form is returned, the Token is validated. If validation fails, then the form has already been submitted, and the user can be apprised. 1. saveToken(request) 2. on the return trip,

3. isTokenValid(request) 4. resetToken(request)

What is the purpose of Struts ? How differ from JSP ? For a WEB APPLICATION run success fully still now we r following many design patterns. Such as front controller, application controlor, value object etc . by the sujession of lots of devlopers jakarta makes a frame work implementing commonly and reliable design patterns as a Struts Framework to give a common strategy. Struts implemented ActionServlet as front Controlor, request processor as application controlor, ActionFotrm as value object. Action class as a SingleTon class (some whwere I read it) etc. It differs from JSP as we donot write <jsp:usebean>tag to set or get the properties in FormBean struts frame work does this 4 us. Actually Struts is based on MVC architecture which ease the developer work by separate the Model, View and Controller components. In struts, we need not to write any business logic in jsp pages. We make it as pure view component. ***********************8

Brief Introduction about Hibernate ?

We are using JDBC API in Java to communicate with DataBase. Instead of using JDBC API we can use Hibernate to communicate with the DataBase. - Hibernate is a solution for ORM (Object Relational Mapping) and a persistence management solution or persistent layer. - Hibernate give a solution to map DataBase tables to a Class. It converts the DataBase tables to a Class data. - Hibernate is the most mature and most complete open source Object Relational Mapper. It is widely used and very actively developed. Brief Introduction about Hibernate ? Hibernate is an opensource light weigt ORM tool to develop Database Independent O-R Mapping based persistance logic in Java Based Enterprise Applications. Hibernate is usefull because it lowers the writing of sql statements but nowadays ibatis is comes in to act so lets try ibatis read the tutorial here http://www.s2sgateway.com

You might also like