A Techno Blog, mainly about Java


JavaServer Pages Standard Tag Library (JSTL)

It says the the jwsdp kit which I downlaoded recently includes JSTL. Since the Web Services Pack supports a JSP 2.0 container and makes all JSTL jar files globally available to all web applications, you are all set to immediately take advantage of JSTL 1.1. In the JSTL lib folder within jwsdp their is a jstl.jar file.

The constituent tag libraries of Standard Taglib are as follows:

1. Core <c:tagname … >

2. XML processing <x:tagname … >

3. I18N capable formatting <fmt:tagname … >

4. Database access (SQL) <sql:tagname … >

5. EL Functions fn:fnname …

August 11, 2004 Posted by | Servlets & JSP | Leave a comment

Servlets – reference info

Introduction to servlets

JSP Expression  <%= expression %> Expression is evaluated and placed in output.

JSP Scriptlet  <% code %> Code is inserted in service method.

JSP Declaration <%! code %> Code is inserted in body of servlet class, outside of service method.

JSP page Directive <%@ page att="val" %>  Directions to the servlet engine about general setup.

Implicit objects:

  • import="package.class"
  • contentType="MIME-Type"
  • isThreadSafe="true|false"
  • session="true|false"
  • buffer="sizekb|none"
  • autoflush="true|false"
  • extends="package.class"
  • info="message"
  • errorPage="url"
  • isErrorPage="true|false"
  • language="java"

JSP comment <%– comment –%> Comment; ignored when JSP page is translated into servlet.

Several local variables are automatically declared by JSP:

  • request – javax.servlet.http.HttpServletRequest
  • response –  javax.servlet.http.HttpServletResponse
  • session – javax.servlet.http.HttpSession
  • config – javax.servlet.SErveltConfig
  • application – javax.servlet.ServletContext
  • out – javax.servlet.jsp.JspWriter

JavaServer Pages (JSP) technology provides you with a simple way to
build and maintain web pages with dynamically generated content.

JSP technology allows you to change the code that deals with the
dynamic content of a web page while leaving the HTML that deals
with the static content unchanged.

Your JSP page includes both standard HTML or XML tags and
special JSP tags.

JSP technology supports both standard and user-defined JSP tags.

JSP 101
A beginners guide.

JSP tutorial starts from simple examples and progresses to complex concepts.

Java Server Pages
Tutorial based on Sun Core Servlets and JSP book.
Servlet section is here.

Two key HTTP Request methods:

GET – Get a file and return its contents. In the context of a servlet, means send some dynamic content to the user as html.

POST – Used to send data to the server. It happens usually when you type some information into a html form and click the submit button.   

HTTP Responses:

Contains the HTTP version followed by a numeric 3 digit status code, and its associated textual phrase (for debugging purposes).
1xx :Informational – request recieved, continuing process
2xx : Success – action was successfully recieved, understood, and accepted.
3xx : Redirection: further action needed to complete the request.
4xx : Client Error – request contains bad syntax or cannot be fulfilled.
5xx: Server Error – sever failed to fulfill an apparently valid request.

/servlet/ part of the client URL.

javax.servlet package – Contains the Servlet interface.

Most servlets extend either GenericServlet or HttpServlet and override some or all of their methods with appropriate customized behaviors:

javax.servlet.GenericServlet- Defines a generic, protocol-independent servlet. It implements the Servlet and ServletConfig interfaces.To write a generic servlet, you need only override the abstract service method.

javax.servlet.http.HttpServlet – Web based servlets typically extend class HttpServlet class and must override at least one method, usually one of these:

  • void init( servletConfig config ) – this method is automatically called once during the servlet’s execution cycle to initialize the servlet.
  • void service( ServletRequest request, ServletResponse response ) – this is the first method called on every servlet to respond to a client request
  • void destroy() – this cleanup method is called when servlet is terminated by the server on which it is executing.
  • String get ServletInfo() – this method is defined by a servlet programmer to return String containing servlet information such as the servlet’s author and version.
  • doGet( ServletRequest request, ServletResponse response ), responds to an HTTP Get requests from a client, gets (or retrieves) information from the server (e.g., an HTML document or an image).
  • doPost( ServletRequest request, ServletResponse response ), respond to a HTTP Post requests from a client, a post request posts (or sends) data to the server (i.e., to send the server information from a HTML form in which the client enters data) so it can search the internet or query a database. 

The arguments HttpServletRequest and HttpServletResponse:

javax.servlet.http  (HttpServletRequest Interface) – Extends the ServletRequest interface:
getParameter – Returns the value of a request parameter. For HTTP servlets, parameters are contained in the query string or posted form data.
getAttribute – Returns the value of the named attribute as an Object.
setAttribute – Stores an attribute in this request.

javax.servlet.http  (HttpServletResponse Interface) – Extends the ServletResponse interface:
setContentType – Sets the content type of the response being sent to the client. The content type may include the type of character encoding used, for example, text/html;
Requests between servlets
jsp fwd action

August 11, 2004 Posted by | Servlets & JSP | Leave a comment