Open the-jsp and operating principle of the Java EE (iv.)

Source: Internet
Author: User

Understanding of JSP


Full name Java Server pages, which implements dynamic Web pages by nesting Java code in HTML.

You can get to know the JSP from the following four aspects:

1. Dynamic Content Templates

of Dynamic HTML , accepting requests to process customers, you can populate different business logic.

2. Using a customJavaCode ExtensionHTML

The essence is the dynamic updating of tags. JSP generates tag code that can be HTML or Other tag languages such as XML.

3. is compiled intoServlet

Essence is Servlet , during the development phase JSP is a template-based language for text scripts, and the runtime is compiled into Servlet the format, the life cycle of the execution, and Servlet fully consistent .

4work is divided into content creation and program development.

HTML or XML can be developed with other tools JSP The work of content, the use of dynamic implementation JSP its own markup to develop, such as adding instructions and behaviors to augment the parts of dynamic content.

Request Handling Process

We know the nature of the JSP or the servlet,JSPis the difference betweenJSPis toJavathe code is nested intoHTMLcode, although it is nested within theHTMLin, butJSPservice-side), becauseJSPto go throughJSPcontainers, such asTomcat, the role is toJSPtranslates toServlet) (compiled into aClassfiles),and then generate the corresponding HTML code based on the running results of these dynamic code,eventually inin the browserinHTMLform is displayed.

Can be represented by such a flowchart:



Start from Login


Just said that JSP is embedded in the HTML Java Code implementation of dynamic Web pages, but when the HTML page is too large, and there are many static requests that do not need to go through the container, nested Java code in HTML, after the above described in the operation process, the overall speed will obviously have an impact, In order to quickly and easily develop the dynamic Web site, JSP has made a lot of improvements, making it the first choice to quickly build a cross-platform dynamic website.


Simple Landing implementation:


1. Landing Page login.html

  

<p><form action= "logincheck.jsp" method= "POST" > </p><p> user name: <input type= "text" Name= "ID" & gt;<br> </p><p> Password: <inputtype= "text" name= "PWD" ><br> </p><p> <in Put type= "Submit" value= "Login" ><br> </p><p><form></p>
 

2. Login Verification logincheck.jsp


<%if (Request.getparameter ("ID")! = null &&request.getparameter ("PWD")! = NULL) {String id =  Request.getparameter ("ID");  String pwd =request.getparameter ("pwd");    if (Id.equals ("a") && pwd.equals ("a")) {  %> login succeeded!    <%} else {%> login failed! <%}}%>


When to use a servlet, when to use a JSP?


Contact: Essentially a Servlet
  Comparison:

1.Servlet: Processing business logic (as long as it interacts with the database) is easy and easy to display and cumbersome for the user.
2.JSP: Display content to the user simple and convenient, processing business logic (as long as the database to interact with) cumbersome.


It can be explained that the Servlet and JSP , although the implementation of the same function, but their advantages and disadvantages are complementary, so the general situation is to use the JSP and Servlet a

To achieve a complementary state.

For example: Complete the registration function, first display the registration page to the browser, with the JSP Implementation (reg.jsp), fill out the registration information submitted, with the Servlet to implement (Regservlet), registration failed to display error messages and registration page, with JSP to implement (reg.jsp); Successful Registration the display success Information and login page is implemented with JSP (login.jsp).


Summary

JSP and Servlet in the beginning of the understanding of no difficulty (also because of the B/s basis), in the implementation of the servlet and JSP in the process, to eclipse, Tomcat, and so on, the configuration and use of these tools, various versions of compatibility, mainly these issues, The reason is not familiar with their own, but like the original use of UML tools, using VS, is a process from the recognition to the use of proficiency, continuous use, continuous research, always for me.





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.