Servlets – reference info
JSP Expression <%= expression %> Expression is evaluated and placed in output.
JSP Scriptlet <% code %> Code is inserted in
JSP Declaration <%! code %> Code is inserted in body of servlet class, outside of
page Directive <%@ page att="val" %> Directions to the servlet engine about general setup.
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.
A beginners guide.
JSP tutorial starts from simple examples and progresses to complex concepts.
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.
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
ServletConfig interfaces.To write a generic servlet, you need only override the abstract
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
– 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
– setAttribute – Stores an attribute in this request.
javax.servlet.http (HttpServletResponse Interface) – Extends the
– 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,
Requests between servlets
jsp fwd action
No comments yet.