Javaweb Programming (ii) JSP built-in objects

Source: Internet
Author: User
Tags browser cache tomcat server

Embed Java code in 1.jsp:html.
2.JSP Execution Process:
The client sends the request through the browser;
The request JSP file that is obtained by the Web container is translated into a. java file; (servlet file)
A. java file is then compiled into a. class;
Finally executes the. Class and responds to the client for rendering.

What are the stages of the 3.JSP execution process:
Request phase
Translation phase
Compile phase
Implementation phase
4.jsp page Element composition

static text (HTML)
Directive <%@%> (for example: <% @page%>,<% @include%>)
Expression <%=%>
Small script/java Code <%%>
Statement <%!%>
Comments
Client Comment:<!--This is a comment, but the client can view the
Server Note: <%--This is also a comment, but the client cannot see--%> recommended

5.web Program Access is not error-handling scheme
1). Tomcat environment has no problem;
2). Project has not been deployed;
3). tomcat has no boot;
4). URL access is not correct (the file is misplaced, such as placed in the folder under the non-access, such as: Web-inf or meta-inf under);
5). Delete browser cache;
6). Delete Tomcat under \work\catalina\localhost find the item name to access to delete.

6.jsp built-in objects (9)
Request
Reponse
Session
Application
Out

PageContext
Page
Config
exception

7.request: encapsulates the requested parameter
Request.getparameter a message to get a property
Request.getparametervalues get a set of information
Post method garbled processing:
a). Tomcat Server.xml Sets the character set encoding (uriencoding= "Utf-8"), but does not necessarily start the effect; then it needs to be resolved by the following B) method.
<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443" uriencoding= "Utf-8"/>
B.) Post method to submit garbled processing, must be set before using the request, garbled party can be resolved
Request.setcharacterencoding ("Utf-8");
String username=request.getparameter ("UserName");
String userpwd=request.getparameter ("userpwd");
Get Way garbled processing:
New String (Username.getbytes ("iso8859-1"), "Utf-8")
8.response: Responds to customer requests and outputs information to clients
redirect
Response.sendredirect ("success.jsp");//redirect (client), Address bar changed
Request Forwarding
Request.getrequestdispatcher ("login.jsp"). Forward (request, response);//forwarding, Address bar unchanged (server-side forwarding)
The difference between redirection and request forwarding:
Forwarding is a function on the server side, through the forward method to pass the submission information across multiple pages, because the server internal control transfer, so the browser address bar will not show the address after the turn.
Redirection is a function of the client, by requesting a new address to implement the page steering, in the address bar can display the post-turn address.

9.out: Output content to the page.

10. Configuration of the error page (config in Web. xml)
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
11.include instruction
Include the contents of another page on one page
<%@ include file= "dologin_bak.jsp"%>

Javaweb Programming (ii) JSP built-in objects

Related Article

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.