JSP参数传递兼EL表达式
1.浏览器?方式传递参数
/**
浏览器地址栏输入?方式传递参数
?test=123
*/
可以用${param.test}方式输出
2.页面内部设置参数setAttribute
/**
JSP页面中输入
<% request.setAttribute("test2", "1234");%>
传递参数
*/
可以在页面代码中输入以下方式输出:
${requestScope.test2}
<%=request.getAttribute("test2") %>
3.servlet设置request参数的访问:
import java.io.IOException; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class TestRequest extends HttpServlet{
void TestRequest(){
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String test2=new String("aaaaa");
request.setAttribute("test2", test2); RequestDispatcher dispatch = request.getRequestDispatcher("/index.jsp"); /*设置跳转页面*/
dispatch.forward(request, response); /*转发request数据到目标页*/
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
servlet代码
/*JSP代码*/
<body>
This is my JSP page. <br>
${param.test2}
<%=request.getParameter("test2") %>
${requestScope.test2}
<%=request.getAttribute("test2") %>
</body>
/**
访问网址
http://localhost:8080/Test/TestRequest?test2=3333
后运行结果
*/
This is my JSP page.
3333 123456 123456
也就是说
${param.和<%=request.访问url传递的参数
${requestScope.和<%=request.访问的是servlet传递的参数
KEY:
关键 ${requestScope.*},是jsp内置对象,和request.getAttribute相似,都是取得现有的后台的数据
参考:关于EL表达式中requestScope和param区别
JSP参数传递兼EL表达式的更多相关文章
- 解决JSP 不解析EL表达式
解决JSP 不解析EL表达式,jsp在使用EL表达式的时候发现它不被解析,而是直接以字符串的形式显示了出来,经过查阅资料和实践,终于得知了原因并找到了解决方案 原因是:在默认情况下,Servlet 2 ...
- jsp页面用el表达式获取枚举的code
jsp页面用el表达式获取枚举的code <c:set var="D_BUSINESS" value="<%=DeptEnum.D_BUSINESS%> ...
- JSP页面用EL表达式 输出date格式
JSP页面用EL表达式 输出date格式 1.头上引入标签 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix ...
- jsp中的el表达式没有解析
今天发现jsp中的el表达式没有解析,把解决的过程记录一下 在web.xml的web-app节点的版本改成2.4以上
- springmvc用model传值到jsp页面,el表达式引用接收不到传递过来的值
springmvc用model传值到jsp页面,el表达式引用接收不到传递过来的值 查看下controller层代码可以发现,写的是没有错误的. @RequestMapping("list. ...
- jsp不解析el表达式,不识别jstl标签,找不到http://java.sun.com/jsp/jstl/core
问题描述: jsp页面中el表达式,例如:${pageContext.request.contextPath},原样呈现,未被解析. 解决方案: 为jsp页添加page指令如下: <%@ pag ...
- jsp页面通过EL表达式获取list大小兼容性处理
1.jsp页面通过EL表达式获取list大小,中间件用tomcat7时,下面这个写法是可以的 <input id="test" type="hidden" ...
- JSP页面使用EL表达式出现的问题:javax.el.PropertyNotFoundException: Property 'ID' not found on type java.lang.Str
问题描述: 1. 后台返回到JSP前台的的list,在jsp页面使用EL表达式遍历时出现如下问题:javax.el.PropertyNotFoundException: Property 'ID' n ...
- JSP标签和EL表达式
1.jsp标签: sun原生的,直接jsp使用 <jsp:include> -- 实现页面包含,动态包含 <jsp:include page="/index.jsp&quo ...
随机推荐
- 智能社区--HI3516C可视门禁研发出来咯
铝壳.非常大气的外壳. 200W像素,HI3516C,携带server.创新的产品.欢迎交流:QQ237753582 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...
- Swift—使用try?和try!区别-仅供参考
在使用try进行错误处理的时候,经常会看到try后面跟有问号(?)或感叹号(!),他们有什么区别呢? 1.使用try? try?会将错误转换为可选值,当调用try?+函数或方法语句时候,如果函数或方 ...
- union关键字及大小端模式
1. union 关键字 union 维护足够的空间来置放多个数据成员中的“一种”,而不是为每一个数据成员配置空间,在 union 中所有的数据成员共用一个空间,同一时间只能储存其中一个数据成员,所有 ...
- CF#315 C
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...
- BestCoder Round #56/hdu5463 Clarke and minecraft 水题
Clarke and minecraft 问题描述 克拉克是一名人格分裂患者.某一天,克拉克分裂成了一个游戏玩家,玩起了minecraft.渐渐地,克拉克建起了一座城堡. 有一天,克拉克为了让更多的人 ...
- exception log
except Exception as e: l = [str(i) for i in [dbid, f_mp3, e]] log_s = '||'.join(l) logging.exception ...
- 代理ip 测试
Line #1218 : 101.232.208.245 - - [16/Jan/2018:02:47:34 +0800] "GET /?xltestdesfs HTTP/1.1" ...
- cssTest
html <!doctype html> <html> <head> <meta charset="utf-8"> <meta ...
- 国产手机没有google services 和google play崩溃,判断google services是否存在
public static boolean isGooglePlayServiceAvailable (Context context) { int status = GooglePlayServic ...
- PDO连接mysql8.0报PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers错误
安装mysql8.0之后,尝试使用php连接mysql,总是报PDO::__construct(): Server sent charset (255) unknown to the client. ...