Servlet Basics Grooming (I.)

Source: Internet
Author: User
Tags html comment

nearly one months did not see the servlet, coupled with the first study did not go into, just a general look over, made up a bit of the basic case has passed, and now go to see the feeling and did not learn the same. Here again with a little time to comb these basics, deepen the impression and prepare for a quick review, after all, this is a fast-paced society, everything to quickly do the groundwork.

First, make it clear that the basic servlet programming role is assumed in enterprise applications. If you do not consider using other frameworks to develop, I think the implementation of the MVC Architecture Division should be M:javabean, v:jsp, C:servlet. As a special servlet. JSP because of its own characteristics, acting as the responsible collection of user requests, presenting data to the user, intermediate data processing links to the servlet processing.

This article is to tidy up some scattered knowledge points.

Well, get into the Special foundation section: Getting Started with JSP Basics:

comments and declarations:

<!--HTML comment-->//on the page to view the source code display <%--jsp comments--%>//<span style= "font-family:arial, Helvetica, Sans-serif;" > on the page to view the source code does not display </span><%! JSP declaration   int i;%><% out.println (i++)%><table bgcolor= "#9999dd" border= "1" width= "300px" ><% for  (int i=0;i<5;i++)  {%>  <tr><td> <%=i%> lines </td>  <td>hello</td></tr>  <%   }%>

three compiler directives for JSP:

    1. Page
      Define some of the property issues on this page. For example:
      <%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    
      Here, if there is an error page, you need to set the error page erorpage= "error.jsp" iserrorpage= "true" in error.jsp.
    2. Include: include other pages dynamically
      <jsp:include page= "/index.jsp" >  <jsp:param value= "123" Name= "key"/></jsp:include>
    3. Taglib: Label
      Define the labels used in the page: for example
      <%@ taglib prefix= "s" uri= "/struts-tags"%>
JSP nine built-in objects:

This is mainly about Application+session+request+response. Where application is within the scope of the entire project, the session scope is a user session, and request is a user demand. Here is an example of setting the properties of three scopes:

<% Application.setattribute ("Key1", "Hello");   Session.setattribute ("Key2", "Hello");   Request.setattribute ("Key3", "Hello");%>

Since this is response, let's talk about forwarding and redirection. Forwarding is the same request, the properties within the request can be valid, and the page URL will not change. Redirection is a new user request, and the URL changes. Basic implementation code:

Request.getrequestdispatcher ("login.jsp"). Forward (request, response); Response.sendredirect ("login.jsp");

OK, this is a beginning, a brief introduction of the JSP several knowledge points, the following is written in the servlet section.


Servlet Basics Grooming (I.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.