如何使用JSP读取URL中传递的请求参数?
以下URL将使用GET方法将两个值传递给HelloForm程序。
href=“http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI”
下面是main.jspJSP程序,用于处理Web浏览器给出的输入。我们将使用getParameter()方法,这使得访问传递的信息非常容易-
<html>
<head>
<title>Using GET Method to Read Form Data</title>
</head>
<body>
<h1>Using GET Method to Read Form Data</h1>
<ul>
<li><p><b>First Name:</b>
<%= request.getParameter("first_name")%>
</p></li>
<li><p><b>Last Name:</b>
<%= request.getParameter("last_name")%>
</p></li>
</ul>
</body>
</html>现在,在浏览器的Location:box中输入href=“http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI”。这将产生以下结果-
使用GET方法读取表单数据
名:ZARA
姓氏:ALI