当前位置: 移动技术网 > IT编程>开发语言>Java > 在jsp页面如何获得url参数

在jsp页面如何获得url参数

2017年12月12日  | 移动技术网IT编程  | 我要评论
当一个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});
});

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网