jsp页面获得url参数的方法
例如,当一个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中。
例子:
依据此逻辑,在使用jquery时,也可以用同样的方法得到,例如:
alert(${param.name});
});
您可能感兴趣的文章:
JSP常见问题
jsp页面获得url参数的方法
servlet与jsp基础教程(11)-JSP及语法概要
jsp常见问题二
JSP 怎么提高数据库访问效率
Js 取得当前页面的URL网址参数
servlet与jsp基础教程(12)-脚本元素、指令和预定义变量
JSP面试题与答案讲解
JSP入门教程(3)-HTML表单
javascript 获取url参数的小例子