Servlet BASICS (1): servlet Basics

Source: Internet
Author: User
Tags html comment

Servlet BASICS (1): servlet Basics

I haven't looked at servlet for nearly a month, and I haven't gone deep into my first study. I just read it all in a general sense. After compiling some basic cases, I feel like I have never learned it. Here, I will take a moment to sort out these foundations, deepen my impressions and prepare for future quick review. After all, this is a fast-paced society, and everything is quickly paved the way.

First, it is clear that the basic servlet programming plays a role in enterprise applications. If you do not consider using other frameworks for development, I think the division of labor for implementing the MVC Architecture should be M: javaBean, V: jsp, C: servlet. As a special servlet. Due to its own characteristics, jsp acts as responsible for collecting user requests and presenting data to users. The intermediate data processing process is handed over to servlet for processing.

This article organizes some scattered knowledge points.

Now, go to the special basics section: JSP basics:

Comments and declarations:

<! -- HTML comment --> // view the source code display on the page <% -- Jsp comment -- %> // <span style = "font-family: Arial, Helvetica, sans-serif; "> the source code is not displayed on the page </span> <%! // Declare int I; %> <% out. println (I ++); %> <table bgcolor = "# 9999dd" border = "1" width = "300px"> <% for (int I = 0; I <5; I ++) {%> <tr> <td> row <% = I %> </td> <td> hello </td> </tr> <%} %>

Three jsp compilation commands:

Nine built-in jsp objects:

Here we mainly talk about application + session + request + response. The application is within the entire project, the session is a user session, and the request is a user request. The following example sets the attributes of three ranges:

<% application.setAttribute("key1", "hello");   session.setAttribute("key2", "hello");   request.setAttribute("key3", "hello");%>

Now that response is involved, let's talk about forwarding and redirection. Forwarding is the same request. The attributes in the request are valid and the page url is not changed. 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 an opening section. It briefly introduces several knowledge points of jsp. The servlet section is written below.
 

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.