在jsp页面如何获得url参数
2017-12-01 14:48
295 查看
当一个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});
});
<%
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});
});
相关文章推荐
- 在jsp页面如何获得url参数
- 在jsp页面如何获得url参数
- 在jsp页面如何获得 url 参数
- 在jsp页面如何获得url参数
- 日常问题记录--jsp中struts2标签如何获取当前页面的url参数
- url传参数到jsp页面,jsp页面如何接收?
- 在jsp页面获得url参数的方法
- jsp如何获取url中的参数并且防止中文乱码以及如何先执行servletzai执行jsp页面
- 在struts2中如何接收jsp页面url传过来的参数
- js父子窗口传值以及当前页面在js前台如何获得url参数
- Jsp页面获得url参数的方式
- Jsp页面获得url参数的方式
- 在jsp页面获得url参数的方法
- 如何在JSP页面上直接获取url的参数呢(不通过controller设置)?
- 在一个jsp页面接收另一个jsp页面通过URL方式传过来的参数
- 在jsp页面获取url请求参数
- 皕杰报表在JSP页面中如何传递参数和变量
- js javascript 获取url,获得当前页面的url,静态html文件js读取url参数
- jsp页面 URL传中文参数到Action里面出现乱码