在javaWeb开发中jstl和EL表达式是经常用到的技术,其中el表达式的param隐藏参数用来获取或保存url的参数更是是常用的开发技术.下面就来看看EL表达式是怎么来获取URL的参数的吧,你会发现这其实相当的容易
inputpage.jsp
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>测试EL表达式的param用法</title>
</head>
<body>
${param.age }
<form action="param2.jsp" method="get">
<input type="hidden" name="age" value="18"/>
<input type="hidden" name="city" value="HK"/>
username:<input type="text" name="username"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
保存了两个隐藏字段,还有username的一个输入框,在里面输入Robot,再提交到另一张页面
param2.jsp
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
<h4>这是对接受参数EL表达式param的测试</h4>
<%= request.getServerName() +":"+ request.getServerPort() +"/"+ request.getContextPath() %><br>
<%= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/" %><br>
param.none-- ${param.none }<br>
param.age-- ${param.age }<br>
param.username-- ${param.username }
<hr>
<a href="http://localhost:8080/s-actionform/elparam/param2.jsp?otherinfo=Beatiful&word=Great">点击<a><br>
otherinfo== ${param.otherinfo }<br>
word== ${param.word }
</body>
</html>
当从inputpage.jsp跳转过来的时候,你就会发现在param2.jsp上会显示隐藏的字段值,和你输入的username参数,当你点击另一个链接的时候,就会发现这些值就又不见了。因为param又重新去截取了一个新的URL里面的参数!