URL ต่อไปนี้จะส่งสองค่าไปยังโปรแกรม HelloForm โดยใช้วิธี GET
href="http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI"
ด้านล่างนี้คือ main.jsp โปรแกรม JSP เพื่อจัดการอินพุตที่กำหนดโดยเว็บเบราว์เซอร์ เราจะใช้ 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> ตอนนี้พิมพ์ href="http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI" ใน Location:box ของเบราว์เซอร์ของคุณ . สิ่งนี้จะสร้างผลลัพธ์ดังต่อไปนี้ -
การใช้วิธี GET เพื่ออ่านข้อมูลในแบบฟอร์ม
|