Suppose you are familiar with some beginner concepts regarding Servlet and Java Server Pages (JSP), this article focuses on some techniques for making JSP and Servlet working together in a Java web application. A brief overview of Servlet and JSP technologies
A Servlet is a Java class running on a web server to serve client’s requests. Servlets are commonly used to handle HTTP requests. They are created to address shortcomings of CGI scripting, and enhance functionality
• Cache static data using jspInit() method.
• Release static data in jspDestroy() method.
• To concatenate string use, StringBuffer.
• Do not use println() method.
• Do not use PrintWriter to send binary data. Use ServletOutputStream.
• Always flush data in sections.
• Use getLastModified() method to handle browser and server cache.
• Use application server cache.
• Use session in following order: HttpSession, Hidden fields, Cookies, URL rewriting.
Servlet is a Java program that runs on a web server to handle requests and returns response to clients. It is widely used for Java enterprise development, and Eclipse is one of the best IDE for Java development. So this article will walk you through a Java project using Eclipse IDE to create a web application that plays around with a Java servlet. Set up Eclipse development environment
The following software programs are required to be installed on your computer:
Hidden Fields present on the pages are able to maintain the state. They are not able to be seen on browsers. The servers treat both non-hidden and hidden fields in similar way.
<INPUT type=”hidden” name=”Firstname” value=”Peter”>
<INPUT type=”hidden” name=”Lastname” value=”Smith”>
The hidden field’s disadvantage is that they might expose certain private or sensitive information, to others.
Updated 01-14-2012 at 05:56 PM by Servlet
Responses and requests are intercepted dynamically by a filter so that to transform the information present in responses of requests. However, responses are not typically created by them. For transformation of the response from JSP or Servlet filters are used before it is sent back to client. Reusability gets improved by the filters by placement of the recurring tasks as a reusable unit in the filter.
Better way of thinking servlet filters is to consider steps whose response is sent
Updated 01-15-2012 at 07:37 AM by Servlet
In order to manage the life cycle of a Servlets, Web container is mainly responsible. Servlets instance gets created by the web container which calls the init() method. At init() method completion, Servlets is present in a ready state to service the requests from client. Servlets service method is being called by container to handle every request, by spawning new threads. For every request, from thread pool of the web container there also exists the possibility to have one threaded servlet. Before
Updated 01-15-2012 at 07:38 AM by Servlet
One of the recommended approaches is HTTP session. A request is being identified by the session which is originated from similar browser during the conversation time period. Same session could be shared by all servlets. The JSESSIONID gets generated by server and is passed via cookies to the client, Built in SSL mechanism or URL rewriting (if cookies get off). For minimizing the object’s size stored in session, care shall be taken. To obtain the session in Java servlet proceed as following:
Updated 01-15-2012 at 07:35 AM by Servlet
Downloading files is a very popular task on the World Wide Web. Users click on a download link and the file gets downloaded into their computer. Technically, a download can be achieved by either of the two forms as following: Direct link: the link points directly to a file on a server, for example: http://www.server.com/download/report.xls. This kind of link requires no additional effort on the server side, since the web server automatically hands the file over to users as
Uploading files is a common operation for internet applications. Doing so in Java is pretty simple. This article will guide you through some steps to write a Java servlet that uploads a file then store it on the server.
Before going on, this article assumes that you have some Java web development experience, you are be able to use Eclipse IDE to write the code and deploy a web application on Tomcat 6.0 server.
The web application we are going to build contains the following components:
If you are programming in java on the back end, one of the key enabling technologies that you must know is servlets. Basically a servlet is a class that handles HTTP responses and makes HTTP Requests. I’m going to assume that you know enough about servlets to be able to override doGet and doPost in order to do some useful work (generate HTML) with your servlets, but what you might not know is the servlet lifecycle. I outline this below in order to improve your understanding how servlets work and
Let us see how to configure the struts-config.xml file to map the request to some destination servlet or jsp file.
The class org.apache.struts.action.ActionServlet is at 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.
<!-- Standard Action Servlet Configuration (with debugging) --> Java Code: <servlet>
In this post, I will present an example which will show how to move the selected file (drop down menu) form a servlet to another servlet which performs operations on the file.
I have created 3 Javafiles namely:
- GetImg (Servlet)
- ImgCompare (simpleJava class)
HelloServlet contains a HTML form that has a dropdown menu. Menu contains 2 JPG files. You should have following images at the given path: