在jsp页面如何获得url参数

如题所述

当一个url过来时,如:具体路径/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>中显示。 

解释说明:

request.getParameter是用来获取URL中的参数的

温馨提示:答案为网友推荐,仅供参考