jsp notes

jsp (Java Server Pages) is a new dynamic web technology standard. Java program fragments (Scriplet) and JSP tags are added to traditional web HTML files (*.html, *.htm) to form JSP web pages (*.jsp). When the Servlet/JSP container receives the request from the client, it first execute the program fragment in it,
The execution result is then responded to the client in HTML format.
 
JSP technology is mainly used to represent pages and realize the function of displaying or receiving user input, while servlet technology is mainly used to complete a large number of logic processing.
 
servlet
When writing a servlet, the servlet interface must be implemented directly or indirectly, most likely by extending javax.servlet.genericservlet or javax.servlet.http.httpservlet When implementing the javax.servlet.servlet interface, there are 5 methods that must be implemented
 
JSP built-in object introduction
Privacy objects (built-in objects) are Java class instances automatically created through the JSP mechanism, allowing interaction with the underlying servlet environment. JSP has a series of privacy objects and methods for performing certain functions, such as accessing data from client pages, sending data back, and controlling the buffering of transmitted data. Such as request, response, pageContext, session. . .
 
JavaBean, composed of properties and methods, has the ability to realize code reuse and easy program maintenance.
 
Standard Action Tags in JSP
Actions are represented by <jsp:xxx> in JSP syntax, which can be used to control the actions of the JSP engine. JSP mainly provides the following basic action tags:
Standard Action Label Name
effect
<jsp:include>
Include a file when the page is requested
<jsp:userBean>
Instantiate a JavaBean
<jsp:setProperty>
Set JavaBean properties
<jsp:getProperty>
Get or output the properties of a JavaBean
<jsp:param>
用来提供key/value的信息,可以在<jsp:include>、<jsp:forward>或<jsp:param>动作中使用,指定一个将加入请求的当前参数组中的参数。
<jsp:param>
向一个动态文件发送一个或多个参数
   
 
自定义标签
通过标签可以使JSP网页变得简洁并且易于维护。
创建和使用一个标签的具体步骤如下:
1、创建标签的处理类(Tag Handler Class);
2、创建标签库描述文件(Tag Library Descrptor File);
3、在 web.xml 文件中配置元素
4、在 JSP 文件中引人标签库;
 
EL表达式
语法结构:
${expression}
EL表达式提供.和[]两种运算符来存取数据。
例子:
例如我们要取得用户的请求参数时,可以利用下列方法:
request.getParameter(String name)
request.getParameterValues(String name)
在 EL 中则可以使用 param 和 paramValues 两者来取得数据。
${param.name}
${paramValues.name}
 
JSTL(Java Standard Tag Library 标准标签库)
JSTL简化了JSP和Web应用程序的开发。封装了JSP开发中的常用功能,减少了JSP中的Scriptlets代码数量。
JSTL主要包括以下操作相关的标签:
常用的标签:如<c:out>、<c:set>等
条件标签:如<c:choose>、<c:if>等
SQL 标签:如<sql:setDataSource>、<sql:query>等
URL 标签:如<c:import>等
XML 标签:如<xml:out>等
 
Filter介绍
Filter可认为是Servlet的一种“加强版”,它主要用于对用户请求进行预处理,也可以对HttpServletResponse进行后处理,是个典型的外理链。
 
${pageContext.request.contextPath}
就是取出部署的应用程序名路径或者是当前的项目名称路径
例子:http://localhost:8080/ajax01/login.jsp 
${pageContext.request.contextPath}/login.jsp即可以访问到
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325078403&siteId=291194637
jsp