answersLogoWhite

0

JSP and Servlets

JSP (JavaServer Pages) are Java programs encoded within webpages that research and generate pertinent results. Servlets, on the other hand, are objects (programs) that handle requests from users and provide results based on these requests.

261 Questions

How many interfaces in a java servlet package?

The javax.servlet package defines 12 interfaces, 7 classes, and 2 exceptions. The Interfaces are as follows:

Filter:- Preprocessor of the request before it reaches a servlet. It can also be a postprocessor of the response leaving a servlet. It can modify a request or response (for example, change headers), the request to a resource (a servlet or static content), or the response from a resource.

RequestDispatcher:- This is the servlet version of a redirect. It enables requests to be processed and then forwarded to other components of a Web application, such as another servlet, HTML file, or JSP file.

Servlet:- Defines the life-cycle methods that are implemented by all servlets.

ServletConfig:- This class has the methods for accessing the servlet configuration information such as the servlets name (from the web.xml file), the initialization parameters, and the ServletContext object.

ServletContext:- These methods enable your servlet to communicate with its servlet container. This is how you get the MIME type of a file, dispatch requests, or write to a log file. Notice that this information has application scope. The most important features of the ServletContext are application-scope attributes access, logging, and context initialization parameters.

ServletContextAttributeListener:- Implementations of this interface receive notifications of changes to the attribute list on the servlet context of a Web application. Supports the handling of the ServletContextAttributeEvent class.

ServletContextListener:- An interface that supports the handling of the ServletContextEvent class. Defines a set of methods that a servlet uses to communicate with its servlet container. It can get the MIME type of a file, dispatch requests, or write to a log file. Notice that there is one context per "Web application" per Java Virtual Machine. The specification defines a "Web application" as a collection of servlets and content installed under a specific subset of the server's URL namespace, such as /catalog, and possibly installed via a .war file.

ServletRequest:- This interface forms the base for the class that provides client request information to a servlet. It is protocol-independent.

ServletResponse:- This interface forms the base for the class that represents the response sent from the servlet to the client.

SingleThreadModel:- An interface that ensures a given servlet handles only one request at a time.

How do you set the session variables in jsp?

The session variables can be accessed in a jsp page from the request object.

Note: Accessing session contents in JSP is not a good design practice

How-to clear the session values from the jsp page?

session.invalidate() . But you need to refresh page to take effect. Note that generally that the session truly ends only when the browser window closes.

The six most commonly used methods to invalidate a session are

• Calling HttpSession.setMaxInactiveInterval(int secs) method, explicitly setting how many minutes the session will last.

• The session will automatically be invalid after a certain time of inactivity (Tomcat default is 30 minutes). You need to remember that this 30 minutes is not a hard and fast rule for all servers. It might vary from one server to another and is configurable. So you can have it configured to last 25 mins in your server and I can have it to last 20 mins.

• The user closes all browser windows. Note that, here the session will timeout rather than directly triggering a session invalidation.

• The session will expire when it is explicitly invalidated by a servlet by calling invalidate().

• The server is stopped or crashes. Note that this event might not trigger a session invalidation. A Web container that permits failover might persist the session and allow a backup Web container to take over when the original server fails.

• You can set the default timeout in the web.xml file ().

What is the difference between PHP and CGI?

The benefits of running PHP-CGI are:

*

* It is more secure. The PHP runs as your user rather than dhapache. That means you can put your database passwords in a file readable only by you and your php scripts can still access it!

* It is more flexible. Because of security concerns when running PHP as an Apache module (which means it runs as our dhapache user), we have disabled a number of commands with the non-CGI PHP. This will cause installation problems with certain popular PHP scripts (such as Gallery) if you choose to run PHP not as a CGI!

* It's just as fast as running PHP as an Apache module, and we include more default libraries.

There are a FEW VERY MINOR drawbacks to running PHP-CGI. They are:

*

* Custom 404 pages won't work for .php files with PHP-CGI. Or will they? See n74's comment below!

* Variables in the URL which are not regular ?foo=bar variables won't work without using mod_rewrite (http://httpd.apache.org/docs/mod/mod_rewrite.html) (example.com/blah.php/username/info/variable).

* Custom php directives in .htaccess files (php_include_dir /home/user;/home/user/example_dir) won't work.

* The $_SERVER['SCRIPT_NAME'] variable will return the php.cgi binary rather than the name of your script

* Persistant database connections will not work. PHP's mysql_pconnect() function will just open a new connection because it can't find a persistant one.

If one of those is a show-stopper for you, you can easily switch to running PHP as an Apache module and not CGI, but be prepared for a bunch of potential security and ease-of-use issues! If you don't know what any of these drawbacks mean, you're fine just using the default setting of PHP-CGI and not worrying about anything!

Can JSP is used to buid an web application in zope server?

Yes. JSPs can be used as part of any Web Application built/developed using the J2EE Technologies.

What is an applet?

An applet is a small program module which runs under the control of a larger application, for example a web browser.

What is servlet filtering?

The Essentials of Filters The Java Servlet specification version 2.3 introduces a new component type, called a filter. A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. Filters typically do not themselves create responses, but instead provide universal functions that can be "attached" to any type of servlet or JSP page. Filters are important for a number of reasons. First, they provide the ability to encapsulate recurring tasks in reusable units. Organized developers are constantly on the lookout for ways to modularize their code. Modular code is more manageable and documentable, is easier to debug, and if done well, can be reused in another setting. Second, filters can be used to transform the response from a servlet or a JSP page. A common task for the web application is to format data sent back to the client. Increasingly the clients require formats (for example, WML) other than just HTML. To accommodate these clients, there is usually a strong component of transformation or filtering in a fully featured web application. Many servlet and JSP containers have introduced proprietary filter mechanisms, resulting in a gain for the developer that deploys on that container, but reducing the reusability of such code. With the introduction of filters as part of the Java Servlet specification, developers now have the opportunity to write reusable transformation components that are portable across containers. Filters can perform many different types of functions. Authentication-Blocking requests based on user identity. Logging and auditing-Tracking users of a web application. Image conversion-Scaling maps, and so on. Data compression-Making downloads smaller. Localization-Targeting the request and response to a particular locale. XSL/T transformations of XML content-Targeting web application responses to more that one type of client. These are just a few of the applications of filters. There are many more, such as encryption, tokenizing, triggering resource access events, mime-type chaining, and caching. tasks: Querying the request and acting accordingly Blocking the request and response pair from passing any further. Modifying the request headers and data. You do this by providing a customized version of the request. Modifying the response headers and data. You do this by providing a customized version of the response. We'll outline the filter API, and describe how to develop customized requests and responses. Programming the filter is only half the job of using filters-you also need to configure how they are mapped to servlets when the application is deployed in a web container. This decoupling of programming and configuration is a prime benefit of the filter mechanism: You don't have to recompile anything to change the input or output of your web application. You just edit a text file or use a tool to change the configuration. For example, adding compression to a PDF download is just a matter of mapping a compression filter to the download servlet. You can experiment with filters easily because they are so easy to configure. The last section of this paper shows how to use the very flexible filter configuration mechanism. Once you have read this paper, you will be armed with the knowledge to implement your own filters and have a handy bag of tricks based on some common filter types. Programming Filters The filter API is defined by the Filter, FilterChain, and FilterConfig interfaces in the javax.servlet package. You define a filter by implementing the Filter interface. A filter chain, passed to a filter by the container, provides a mechanism for invoking a series of filters. A filter config contains initialization data. The most important method in the Filter interface is the doFilter method, which is the heart of the filter. This method usually performs some of the following actions: Examines the request headers Customizes the request object if it wishes to modify request headers or data or block the request entirely Customizes the response object if it wishes to modify response headers or data Invokes the next entity in the filter chain. If the current filter is the last filter in the chain that ends with the target servlet, the next entity is the resource at the end of the chain; otherwise, it is the next filter that was configured in the WAR. It invokes the next entity by calling the doFilter method on the chain object (passing in the request and response it was called with, or the wrapped versions it may have created). Alternatively, it can choose to block the request by not making the call to invoke the next entity. In the latter case, the filter is responsible for filling out the response. Examines response headers after it has invoked the next filter in the chain Throws an exception to indicate an error in processing In addition to doFilter, you must implement the init and destroy methods. The init method is called by the container when the filter is instantiated. If you wish to pass initialization parameters to the filter you retrieve them from the FilterConfig object passed to init. Example: Logging Servlet Access Now that you know what the main elements of the filter API are, let's take a look at a very simple filter that does not block requests, transform responses, or anything fancy-a good place to start learning the basic concepts of the API. Consider web sites that track the number of users. To add this capability to an existing web application without changing any servlets you could use a logging filter. HitCounterFilter increments and logs the value of a counter when a servlet is accessed. In the doFilter method, HitCounterFilter first retrieves the servlet context from the filter configuration object so that it can access the counter, which is stored as a context attribute. After the filter retrieves, increments, and writes the counter to a log, it invokes doFilter on the filter chain object passed into the original doFilter method. The elided code is discussed in Programming Customized Requests and Responses. public final class HitCounterFilter implements Filter { private FilterConfig filterConfig = null; public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; } public void destroy() { this.filterConfig = null; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (filterConfig == null) return; StringWriter sw = new StringWriter(); PrintWriter writer = new PrintWriter(sw); Counter counter = (Counter)filterConfig. getServletContext(). getAttribute("hitCounter"); writer.println(); writer.println("==============="); writer.println("The number of hits is: " + counter.incCounter()); writer.println("==============="); // Log the resulting string writer.flush(); filterConfig.getServletContext(). log(sw.getBuffer().toString()); ... chain.doFilter(request, wrapper); ... Example: Modifying the Request Character Encoding Currently, many browsers do not send character encoding information in the Content-Type header of an HTTP request. If an encoding has not been specified by the client request, the container uses a default encoding to parse request parameters. If the client hasn't set character encoding and the request parameters are encoded with a different encoding than the default, the parameters will be parsed incorrectly. You can use the method setCharacterEncoding in the ServletRequest interface to set the encoding. Since this method must be called prior to parsing any post data or reading any input from the request, this function is a prime application for filters. Such a filter is contained in the examples distributed with the Tomcat 4.0 web container. The filter sets the character encoding from a filter initialization parameter. This filter could easily be extended to set the encoding based on characteristics of the incoming request, such as the values of the Accept-Language and User-Agent headers, or a value saved in the current user's session. public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String encoding = selectEncoding(request); if (encoding != null) request.setCharacterEncoding(encoding); chain.doFilter(request, response); } public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter("encoding"); } protected String selectEncoding(ServletRequest request) { return (this.encoding); } Programming Customized Requests and Responses Look at a filter that modifies the request from or response back to the client. There are many ways for a filter to modify a request or response. For example, a filter could add an attribute to the request or it could insert data in or otherwise transform the response. A filter that modifies a response must usually capture the response before it is returned to the client. The way to do this is to pass the servlet that generates the response a stand-in stream. The stand-in stream prevents the servlet from closing the original response stream when it completes and allows the filter to modify the servlet's response. In order to pass this stand-in stream to the servlet, the filter creates a response "wrapper" that overrides the getWriter or getOutputStream method to return this stand-in stream. The wrapper is passed to the doFilter method of the filter chain. Wrapper methods default to calling through to the wrapped request or response object. This approach follows the well-known Wrapper or Decorator pattern described in Design Patterns, Elements of Reusable Object-Oriented Software. The following sections describe how the hit counter filter described earlier and other types of filters use wrappers. To override request methods, you wrap the request in an object that extends ServletRequestWrapper or HttpServletRequestWrapper. To override response methods, you wrap the response in an object that extends ServletResponseWrapper or HttpServletResponseWrapper. The hit counter filter described in Programming Filters inserts the value of the counter into the response. The elided code from HitCounterFilter is: PrintWriter out = response.getWriter(); CharResponseWrapper wrapper = new CharResponseWrapper( (HttpServletResponse)response); chain.doFilter(request, wrapper); if(wrapper.getContentType().equals("text/html")) { CharArrayWriter caw = new CharArrayWriter(); caw.write(wrapper.toString().substring(0, wrapper.toString().indexOf("")-1)); caw.write("

\nYou are visitor number " + counter.getCounter() + ""); caw.write("\n"); response.setContentLength(caw.toString().length()); out.write(caw.toString()); } else out.write(wrapper.toString()); out.close(); HitCounterFilter wraps the response in a CharResponseWrapper. CharResponseWrapper overrides the getWriter method to return a stand-in stream into which the servlet at the end of the filter chain writes its response. When chain.doFilter returns, HitCounterFilter retrieves the servlet's response from PrintWriter and writes it to a buffer if it is an HTML response. The filter inserts the value of the counter into the buffer, resets the content length header of the response, and finally writes the contents of the buffer to the response stream. public class CharResponseWrapper extends HttpServletResponseWrapper { private CharArrayWriter output; public String toString() { return output.toString(); } public CharResponseWrapper(HttpServletResponse response){ super(response); output = new CharArrayWriter(); } public PrintWriter getWriter(){ return new PrintWriter(output); } } Example: Compressing the Response Another example of a filter that modifies the response is the compression filter contained in the examples distributed with the Tomcat servlet engine. Although high-speed Internet connections are becoming more commonplace, there is still a need to use bandwidth effectively. A compression filter is handy because you can attach it to any servlet to reduce the size of a response. Like the hit counter filter, the compression filter creates a stand-in stream, in this case CompressionResponseStream, for the servlet to write to and wraps the response passed to the servlet. The filter creates the wrapper and stand-in stream only if the client can accept a compressed response. The servlet writes its response to the compression stream it retrieves from the wrapper. CompressionResponseStream overrides the write method to write response data to a GZIPOutputStream once the data is larger than a threshold passed as an initialization parameter to the filter: public void write(int b) throws IOException { ... if ((bufferCount >= buffer.length) (count>=compressionThreshold)) { compressionThresholdReached = true; } if (compressionThresholdReached) { writeToGZip(b); } else { buffer[bufferCount++] = (byte) b; count++; } } Example: Transforming the Response The last filter we'll discuss is an XSLT filter. XSLT is a language for transforming XML data. You can use XSLT to transform an XML document to end user-oriented formats such as HTML or PDF, or to another XML format. Some example applications include: Converting an XML document in a format required by one company to the format required by another company. Customizing the look and feel of a web page based on user preferences. Enabling the same web application to respond to different types of clients, for example, WML phones and cHTML phones, by looking at the User-Agent header and choosing a stylesheet. Consider a web service that responds to requests for product inventory. The following XML document is an example of such a response: 123 Web Servers for Fun and Profit 10 $17.95 The following XSL stylesheets render this XML document as a user-oriented description of the inventory in HTML format and as a machine-oriented version in XML format. There are copies of available. The following XSLT filter uses the stylesheets to transform the response depending on the value of a request parameter. The filter sets content type of the response according to the request parameter. The response is then wrapped in a CharResponseWrapper and passed to the doFilter method of the filter chain. The last element in the filter chain is a servlet that returns the inventory response described earlier. When doFilter returns, the filter retrieves the response data from the wrapper and transforms it using the stylesheet. public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String contentType; String styleSheet; String type = request.getParameter("type"); if (type == null type.equals("")) { contentType = "text/html"; styleSheet = "/xml/html.xsl"; } else { if (type.equals("xml")) { contentType = "text/plain"; styleSheet = "/xml/xml.xsl"; } else { contentType = "text/html"; styleSheet = "/xml/html.xsl"; } } response.setContentType(contentType); String stylepath=filterConfig.getServletContext(). getRealPath(styleSheet); Source styleSource = new StreamSource(stylePath); PrintWriter out = response.getWriter(); CharResponseWrapper responseWrapper = new CharResponseWrapper( (HttpServletResponse)response); chain.doFilter(request, wrapper); // Get response from servlet StringReader sr = new StringReader( new String(wrapper.getData())); Source xmlSource = new StreamSource((Reader)sr); try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory. newTransformer(styleSource); CharArrayWriter caw = new CharArrayWriter(); StreamResult result = new StreamResult(caw); transformer.transform(xmlSource, result); response.setContentLength(caw.toString().length()); out.write(caw.toString()); } catch(Exception ex) { out.println(ex.toString()); out.write(wrapper.toString()); } ) Specifying Filter Configuration Now that we have seen how to program a filter, the last step is to specify how to apply it to a web component or a set of web components. To map a filter to a servlet you: Declare the filter using the element in the web application deployment descriptor. This element creates a name for the filter and declares the filter's implementation class and initialization parameters. Map the filter to a servlet by defining a element in the deployment descriptor. This element maps a filter name to a servlet by name or by URL pattern. The following elements show how to specify the elements needed for the compression filter. To define the compression filter you provide a name for the filter, the class that implements the filter, and name and value of the threshold initialization parameter. Compression Filter CompressionFilter compressionThreshold 10 The filter-mapping element maps the compression filter to the servlet CompressionTest. The mapping could also have specified the URL pattern /CompressionTest. Note that the filter, filter-mapping, servlet, and servlet-mapping elements must appear in the web application deployment descriptor in that order. Compression Filter CompressionTest CompressionTest CompressionTest CompressionTest /CompressionTest Note that this mapping causes the filter to be called for all requests to the CompressionTest servlet and to any servlet JSP or static content mapped to the URL pattern /CompressionTest. If you want to log every request to a web application, you would map the hit counter filter to the URL pattern /*. Here's the deployment descriptor distributed with the examples: ?xml version="1.0" encoding="ISO-8859-1"?> XSLTFilter XSLTFilter HitCounterFilter HitCounterFilter HitCounterFilter /* XSLTFilter FilteredFileServlet FilteredFileServlet FileServlet FilteredFileServlet /ffs As you can see, you can map a filter to one or more servlets and you can map more than one filter to a servlet. This is illustrated in Figure 1, where filter F1is mapped to servlets S1, S2, and S3, filter F2 is mapped to servlet S2, and filter F3 is mapped to servlets S1 and S2. Figure 1 Filter to Servlet Mapping Recall that a filter chain is one of the objects passed to the doFilter method of a filter. This chain is formed indirectly via filter mappings. The order of the filters in the chain is the same as the order that filter mappings appear in the web application deployment descriptor. When a URL is mapped to servlet S1, the web container invokes the doFilter method of F1. The doFilter method of each filter in S1's filter chain is invoked by the preceding filter in the chain via the chain.doFilter method. Since servlet S1's filter chain contains filters F1 and F3, F1's call to chain.doFilter invokes the doFilter method of filter F3. When F3's doFilter method completes, control returns to F1's doFilter method. The deployment descriptor just discussed puts the hit counter and XSLT filter in the filter chain of FilteredFileServlet. The hit counter filter logs access whenever FilteredFileServlet is invoked, but inserts the value of the counter into the response after the XSLT transformation only if the response type is HTML: Conclusion The filter mechanism provides a way to encapsulate common functionality in a component that can reused in many different contexts. Filters are easy to write and configure as well as being portable and reusable. In summary, filters are an essential element in a web developer's toolkit. Acknowledgments The character encoding filter was developed by Craig McClanahan of Sun Microsystems, the compression filter was developed by Amy Roh of Sun Microsystems, and the XSLT filter was provided by Alan Canon of National Processing Company. Resources You can get the character encoding and compression filters by downloading Tomcat 4.0. The character encoding filter is located in the TOMCAT_HOME/webapps/examples/WEB-INF/classes/filters directory. The compression filter is located in the TOMCAT_HOME/webapps/examples/WEB-INF/classes/compressionFilters directory. You can download a zip file containing the other filters described in this paper from here. To compile and run the XSLT filter, you'll need to obtain an XML parser and transformation engine from http://java.sun.com/xml/download.html For further information about the technologies described in this paper, see the following resources: http://java.sun.com/products/servlet http://www.w3.org/XML http://www.w3.org/Style/XSL http://java.sun.com/xml

What is the difference between an applet and a servlet?

Applet is a part of Core JAVA and Servlet of Advance Java. Applet is client side program and Servlet is Server side. When Applet runs it take the resources of client whereas Servlet is processed at server. An Applet's class, jar files can be accessed and downloadable by client but not so in case of servlet. Applets can run under any web browser their execution is dependent on Client as they require JRE Whereas Servlets do not require any thing specific at client side, as they require java enabled web/application Server. Dilpreet Singh (SCJP,OCA 9i) www.geocities.com/heartsingh
The main difference is that a servlet is a server side component while applet is a client side component, moreover, a servlet doesn't have GUI while applet have GUI. A servlet runs inside a server and results are sent to client, so it consumes less network bandwidth, and also secure, while applet runs on client side in a browser, so entire code for applet is 1st sent to client and then it is executed on the client machine itself, so it also consumes more network bandwidth.

Which pages of the constitution was on display?

The copies, but not the real constitution because its being kept in the meuseum.

How does hibernate work in java?

Hibernate is an object-relational mapping (ORM) library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions.

Hibernate is free as open source software that is distributed under the GNU Lesser General Public License.

Rather than utilize bytecode processing or code generation, Hibernate uses runtime reflection to

determine the persistent properties of a class. The objects to be persisted are defined in a

mapping document, which serves to describe the persistent fields and associations, as well as any

subclasses or proxies of the persistent object. The mapping documents are compiled at

application startup time and provide the framework with necessary information for a class.

Additionally, they are used in support operations, such as generating the database schema or

creating stub Java source files.

Hibernate's primary feature is mapping from Java classes to database tables (and from Java data types to SQL data types). Hibernate also provides data query and retrieval facilities. Hibernate generates the SQL calls and relieves the developer from manual result set handling and object conversion, keeping the application portable to all supported SQL databases, with database portability delivered at very little performance overhead.

MappingMapping Java classes to database table is accomplished through the configuration of an XML file or by using Java Annotation. When using an XML file, Hibernate can generate skeletal source code for the persistence classes. This is unnecessary when annotation is used. Hibernate can use the XML file or the annotation to maintain the database schema.

Facilities to arrange one-to-many and many-to-many relationships between classes are provided. In addition to managing association between objects, Hibernate can also manage reflexive associations where an object has a one-to-many relationship with other instances of its own type.

Hibernate supports the mapping of custom value types. This makes the following scenarios possible:

  • Overriding the default SQL type that Hibernate chooses when mapping a column to a property
  • Mapping Java Enum to columns as if they were regular properties
  • Mapping a single property to multiple columns
PersistenceHibernate provides transparent persistence for Plain Old Java Objects (POJOs). The only strict requirement for a persistent class is a no-argument constructor, not compulsorily public. Proper behavior in some applications also requires special attention to the equals() and hashCode() methods.

Collections of data objects are typically stored in Java collection objects such as Set and List. Java Generics can be used in Java 5 and higher. Hibernate can be configured to lazy load associated collections. Lazy loading is the default as of Hibernate 3.

Related objects can be configured to cascade operations from one to the other. For example, a parent such as an Album object can be configured to cascade its save and/or delete operation to its child Track objects. This can reduce development time and ensure referential integrity. A dirty checkingfeature avoids unnecessary database write actions by performing SQL updates only on the modified fields of persistent objects.

Hibernate Query Language(HQL)Hibernate provides a SQL inspired language called Hibernate Query Language (HQL) which allows SQL-like queries to be written against Hibernate's data objects. Criteria Queries are provided as an object-oriented alternative to HQL. IntegrationHibernate can be used both in standalone Java applications and in Java EE applications using servlets or EJB session beans.

What is the difference between Web UI and Java?

Java Virtual Machine (JVM) is exactly as it's titled, it's just a virtual machine... while Windows is an operating system.

But since the JVM is used to run Java code, it is multi-platform.

What are the steps to increase java heap space on a server?

You can specify the starting and maximum heap sizes when you launch a Java program by using the command line switches:

-Xms<size> set initial Java heap size

-Xmx<size> set maximum Java heap size

Example: The following line will run the MyProgram Java program with 64-128mb heap space.

java -Xms64m -Xmx128m MyProgram

How state Diagram are different from the Activity Diagram?

They are not as they both have the same features it just provides a better understanding when using one diagram in conjunction with the other.

State machine diagram shows how state of some object or system could change, so transitions on the diagram are from one state to another state.

Activity diagram shows set of actions and how one action could lead to another.

In simple cases these diagrams might look like reverse of each other but in practice you need to select whether the diagram is about discrete number of states of some object or is it about organization of actions and activities possibly related to many different objects.

How can you save java servlet program for running?

If ur developing servlet program manually.The First thing is that u have to put servlet-api jar file should be set in classpath. The root directory is like that

create a folder name.inside the folder create one more folder name WEB-INF. Inside the WEB-INF folder create two folders one is classes and another is Lib

In the WEB-INF folder you have to put web.xml. In classes you have to put servlet.java. In Lib u have to put servlet-api.jar file. Go to command prompt then compile servlet.java .Create a war file. steps to create war file file jar cvf name.war . enter .open the browser type the bar http://localhost: portnumber enter & then apache tomcat server start.Click tomcat manager.It will ask username & password.

then submit.In the downstairs page there is a option name War file to deploy .Click on choose file.It will locate where is the war file .Select it & deploy it.click the programs then you have to type in the addresss bar what u had written in url-pattern in web.xml then enter u get the output.

What is the difference between SESSION and POST in PHP?

POST:

Taken from the HTTP 1.0 RFC (#1945:8.3)

The POST method is used to request that the destination server accept

the entity enclosed in the request as a new subordinate of the

resource identified by the Request-URI in the Request-Line. POST is

designed to allow a uniform method to cover the following functions:

o Annotation of existing resources;

o Posting a message to a bulletin board, newsgroup, mailing list,

or similar group of articles;

o Providing a block of data, such as the result of submitting a

form [3], to a data-handling process;

o Extending a database through an append operation.

SESSION:

http://us2.php.net/manual/en/reserved.variables.php#reserved.variables.session

An associative array containing session variables available to the current script. See the Session functions documentation for more information on how this is used.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS.

$HTTP_SESSION_VARS contains the same information, but is not a superglobal. (Note that $HTTP_SESSION_VARS and $_SESSION are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_SESSION and $HTTP_SESSION_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not superglobals.

What is the difference of scfm and cfm?

SCFM is the amount (volume) of air that would happen if your air were at room temperature, and atmospheric pressure (0ft above sea level, 14.7psi). CFM (cubic feet per minute) is the amount (volume) of air that happens at the specific temperature and pressure. example: if you have a balloon that happens to be one cubic foot, and you are inside of a very hot, very high pressre room. when you walk out of the hot room, the flow rate is 1CFM, but because it is a balloon, when you take it outside the room it suddenly expands as it adjusts to outside (close to standard) conditions. So your balloon may be 3 or 4 SCFM. The two are interchangable, but when working in an industry that used flow rates heavily, it's much easier to note SCFM, because it has the added bonus of telling you temperature and pressure along with flow rate.

Can you use struts in a desktop application?

If the desktop application you mean would be run on a web browser - Then the answer is YES. STRUTS is an open source framework used for the development of web based java applications using other J2EE technologies like JSP, Servlets and XML.

Why are servlets more secured?

It is very hard to edit a servlet program using hacking.

Why do you need to override the toString method?

By default every class you write inherently extends the base Object class. This has a basic toString() method which merely returns the name of the class followed by a hex representation of the hash value. By overriding this method, you can return a more meaningful value specific to your class, such as member attributes and their values.

Why jsp cannot be used as mvc controller instead of servlets?

Because JSPs are designed to take care of the View part of the MVC design patter and not the controller. You can have little or some amount of logic in it, but it is not designed/created with the idea of controlling the flow of control in a J2EE application.

How do you make struts action class thread safe?

1.Only Use Local Variables

§The most important principle that aids in thread-safe coding is to use only local variables, not instance variables , in your Action class. Local variables are created on a stack that is assigned (by your JVM) to each request thread, so there is no need to worry about sharing them. An Action can be factored into several local methods, so long as all variables needed are passed as method parameters. This assures thread safety, as the JVM handles such variables internally using the call stack which is associated with a single Thread.

2.Conserve Resources

As a general rule, allocating scarce resources and keeping them across requests from the same user (in the user's session) can cause scalability problems. For example, if your application uses JDBC and you allocate a separate JDBC connection for every user, you are probably going to run in some scalability issues when your site suddenly shows up on Slashdot. You should strive to use pools and release resources (such as database connections) prior to forwarding