在jsp页面如何获得url参数
2015-06-14 19:41
731 查看
当一个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});
});
相关文章推荐
- laytpl.js 模板使用记录
- 再转JavaScript中的this
- 解决.Net MVC EntityFramework Json 序列化循环引用问题.
- JSP中basepath和path的介绍
- JSTL标签的具体介绍—内容多多
- JSON初步
- jsp开发环境搭建(windows64位)
- WordPress文本编辑器自定义功能
- 浅谈JavaScript中的Math.atan()方法的使用
- GIS数据格式topojson
- JavaScript中反正弦函数Math.asin()的使用简介
- js keyup、keypress和keydown事件 详解
- JavaScript中的acos()方法使用详解
- jsp隐藏对象
- 介绍JavaScript中Math.abs()方法的使用
- vs2010 vc jsoncpp 编译要点
- WebBrowser介绍——Javascript与C++互操作
- js日期操作时间看板
- json和js对象之间的互相转换
- fastjson 使用方法