jsp EL表达式详解(2)

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <%-- ${pageContext.request.contextPath }代表web应用的根 --%> <form action="${pageContext.request.contextPath }/regster" method="POST"> xxx<input type="text"/><br> yyy<input type="text"/><br> <input type="submit" value="点击"> </form> </body> </html>

这里写图片描述

2、param(获取请求中的指定参数)

其底层实际调用request.getParameter()

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <%-- ${pageContext.request.contextPath }代表web应用的根 --%> <form action="${pageContext.request.contextPath }/show.jsp" method="POST"> xxx<input type="text"/><br> yyy<input type="text"/><br> <input type="submit" value="点击"> </form> </body> </html>

show.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> name=${param.name }<br> age=${param.age }<br> </body> </html>

客户浏览器访问结果

这里写图片描述

 

这里写图片描述

3、paramValues

获取请求中的指定参数的所以值,其底层实际调用request.getParameterValues()

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <%-- ${pageContext.request.contextPath }代表web应用的根 --%> <form action="${pageContext.request.contextPath }/show.jsp" method="POST"> xxx<input type="text"/><br> yyy<input type="text"/><br> 爱好: <input type="checkbox" value="sleep">睡觉 <input type="checkbox" value="play">玩 <input type="checkbox" value="eat">吃 <input type="submit" value="点击"> </form> </body> </html>

show.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> name=${param.name }<br> age=${param.age }<br> hobby[0]=${paramValues.hobby[0] }<br> hobby[1]=${paramValues.hobby[1] }<br> </body> </html>

客户浏览器显示结果

这里写图片描述

这里写图片描述

4、initParam

获取初始化参数,其底层调用的是ServletContext.getInitParameter()

web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee " version="2.5"> <display-name>07eltttt</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!--初始化参数 --> <context-param> <param-name>name</param-name> <param-value>林杰</param-value> </context-param> <servlet> <display-name>Regster</display-name> <servlet-name>Regster</servlet-name> <servlet-class>linjie.com.Regster</servlet-class> </servlet> <servlet-mapping> <servlet-name>Regster</servlet-name> <url-pattern>/regster</url-pattern> </servlet-mapping> </web-app>

index.jsp

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsgyyp.html