View RSS Feed

Servlet

Servlet tutorials.

  1. Working with JSP and Servlet

    by , 04-03-2012 at 12:44 PM
    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 ...
    Tags: jsp, servlet Add / Edit Tags
    Categories
    Servlet , JSP
  2. Cookies

    by , 01-01-2012 at 05:08 PM
    A cookie is that test of piece which can be stored on the hard disk of a user by web server. Information is being stored on user machine by the help of cookies which is later retrieved. Such information pieces are stored as “name value pairs”. Cookie data gets moved in this way:

    • If URL of a site is typed in the browser, browser will be sending its requests to web server. When this is done by the web browser cookie file is looked for at the machine which has been set by the URL. ...
    Categories
    Cookies
  3. Hidden Fields

    by , 01-01-2012 at 05:07 PM
    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 06:56 PM by Servlet

    Categories
    Field
  4. Explain declarative security for WEB applications

    by , 01-01-2012 at 05:03 PM
    Declarative security is implemented by the Servlet containers. Administration takes place via deployment descriptor web.xml file. Servlets & JSP pages along with the declarative security will become security aware code free. URLs could be protected via web.xml as it has been shown below:

    XML Code: This is a web.xml with the security tags
    <web-app>
    <security-constraint>
    <web-resource-collection>
    <web-resource-name>PrivateAndSensitive</web-resource-name>
    <url-pattern>/private/*</url-pattern>
    ...

    Updated 01-14-2012 at 06:52 PM by Servlet

    Categories
    Security
  5. What is a filter, and how does it work

    by , 01-01-2012 at 04:57 PM
    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 08:37 AM by Servlet

    Categories
    Filter
  6. Servlet Life Cycle

    by , 01-01-2012 at 04:53 PM
    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 08:38 AM by Servlet

    Categories
    Session
  7. HTTP Sessions

    by , 01-01-2012 at 04:50 PM
    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 08:35 AM by Servlet

    Categories
    Session
  8. How to write a Servlet that sends file to user to download

    by , 12-10-2011 at 05:54 AM
    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
    ...
    Categories
    File , Servlet
  9. How to write a Servlet that uploads file to server

    by , 12-10-2011 at 05:19 AM
    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: ...
    Tags: file, servlet, upload Add / Edit Tags
    Categories
    Servlet , File
  10. General Event Handling in Servlets Part 3

    by , 11-29-2011 at 12:35 AM
    In the first two article on general event handling with servlets we have covered how to detect changes in the servlet context and monitoring the creation and destruction of the servlet context. In this last article of the series we will look into how to use listeners with tag libraries. If you have not seen the first two articles of this series, General Event Handling in Servlets, Part 1 and General Event Handling in Servlets, Part 2, then I would recommend that you review them before continuing ...

    Updated 12-09-2011 at 05:16 PM by Servlet

    Categories
    Tutorial , Web , Listener , ServletContextListener
  11. General Event Handling in Servlets Part 2

    by , 11-29-2011 at 12:26 AM
    In the last article, we started to look into the Application Events Framework for servlets and javaserver pages. We listed eight different kinds of events listeners that are related to web application life-cycle events. If you are interested, go review the post, General Event Handling in Servlets Part 1.

    In that article, we looked at the first of the listeners for the initialization and destruction of servlet context and we presented an example of it’s use for a company that is constantly ...

    Updated 12-09-2011 at 05:13 PM by Servlet

    Categories
    Tutorial , Web , Listener , ServletContextListener
  12. General Event Handling in Servlets Part 1

    by , 11-29-2011 at 12:15 AM
    When you are developing applications using servlets or JSP pages, there are a number of tools at your disposal for handling the life cycle of individual servlets or JSP pages. The servlet init method fires when a servlet is first instantiated. With JSP pages it is the jspInit method. Both methods can use initialization parameters that are specified with the init-param subelement of the web.xml servlet element. Requests are handled with service and _jspService, and destruction is handled with destroy ...

    Updated 11-30-2011 at 03:15 PM by Servlet

    Categories
    Tutorial , Web , Listener , ServletContextListener
  13. Reading Request Headers from Servlets

    by , 11-28-2011 at 07:31 PM
    It is relatively easy to read headers. All you need to do is call the getHeader method of HttpServletRequest. If the specified header exists, the servlet returns a String, if not the servlet will return null. Unlike parameter names, header names are not case sensitive. Although getHeader is a general-purpose way to read incoming headers, there are a couple of headers that are so commonly used that they have special access methods in HttpServletRequest. They are listed below.
    • getCookies
    ...
  14. Notes on Form Data for Servlets

    by , 11-28-2011 at 07:25 PM
    When you look at the URL in your web browser if you are using a search engine or on a retail site, you will notice URLs http://host/path?user=James+Rogers&s...rish&sub=music. The part after the question mark (i.e., user=James+Rogers&subj= folk&sub=irish&sub=music) is known as form or query data and is the most common way to get information from a Web page to a server-side program. Form or query data can be attached to the end of the URL after a question mark, for ...
    Categories
    URL Mapping , Form , Tutorial , HTTP
  15. Handling Form Data from Servlets

    by , 11-28-2011 at 07:23 PM
    A feature which is of immense benefits to all programmers working with servlets is that all form data parsing is handled automatically. Rather than needing to build your own called for parsing form data, you only need to call the getParameter method of the Http- ServletRequest, providing the relevant parameter name as an argument. You use getParameter in the same way whether data is sent by GET or by POST. The servlet knows which request method was used and calls the proper method to handle the ...
    Categories
    Tutorial , Form
  16. How to Debug Servlets

    by , 11-28-2011 at 07:07 PM
    Servlets can be difficult to debug because it is not possible to execute them directly. Instead, you trigger their execution by means of an HTTP request, and they are executed by the Web server. For remote execution, inserting break points or reading debugging messages and the stack traces becomes extremely difficult. Here I will outline some strategies to servlet debugging:
    1. Check the HTML source. If it doesn’t look correct, use the “View Source” command in order to check the HTML. If
    ...
    Categories
    Tutorial , HTTP
  17. Know the Servlet Life Cycle

    by , 11-28-2011 at 07:04 PM
    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 ...
    Categories
    Tutorial , HTTP