当前位置:主页 > 查看内容

在jsp页面如何获得url参数

发布时间:2021-06-16 00:00| 位朋友查看

简介:当一个url过来时,如:http://localhost:8080/pro/demo/hello.jsp?name=john,在hello.jsp页面,我们可以这样得到name的值: 复制代码 代码如下: % String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServer……
当一个url过来时,如:http://localhost:8080/pro/demo/hello.jsp?name=john,在hello.jsp页面,我们可以这样得到name的值:
复制代码 代码如下:

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String name = request.getParameter("name");//用request得到
%>

然后在<body>hello:<%=name%></body>中显示

也可以在body中直接用${}得到,因为当使用jstl时,url请求参数被放置到隐含对象param中。所以可以这样写:
复制代码 代码如下:

<body>hello:${param.name}</body>
依据此逻辑,在使用jquery时,也可以用同样的方法得到,如:
$(function(){
alert(${param.name});
});

本文转载自网络,原文链接:https://m.jb51.net/article/46956.htm
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐