How do I get the url parameter on the jsp page
- 2020-10-07 18:50:56
- OfStack
When a url come over, such as: http: / / localhost: 8080 / pro/demo/hello jsp? name=john. On the hello. jsp page, we can get the value of name as follows:
Then, in < body > hello: < %=name% > < /body > In the display.
It can also be obtained directly in body with ${}, because when jstl is used, the url request parameter is placed in the implied object param. So you could write it like this:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String name = request.getParameter("name");// with request get
%>
Then, in < body > hello: < %=name% > < /body > In the display.
It can also be obtained directly in body with ${}, because when jstl is used, the url request parameter is placed in the implied object param. So you could write it like this:
<body>hello:${param.name}</body>
According to this logic, in use jquery , can also be obtained in the same way.
$(function(){
alert(${param.name});
});