jsp頁面中獲取參數值


1.GET方法用根據URL獲取參數值 

1.1 jsp頁面

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <script type="text/javascript" src="js/leave.js"></script>
 3 <%
 4     String flowid = request.getParameter("flowid");   //獲取url中的參數值  5 %>
 6 <html>
 7 <head>
 8     <title>請假審核單</title>
 9 </head>
10 <body>
11     <form id="leave" method="get">
12         <!-- 請假理由 -->
13         <textarea id="reason"></textarea>
14         <input type="hidden" id="flowid" name="flowid" value="<%=flowid%>>"/>
15         <input type="button" value="審核" onclick="commit();"/>
16     </form>
17 </body>
18 </html>

其中flowid是要獲取的參數

1.2 URL

http://localhost:8080/t9/subsys/demo/leave.jsp?flowid=1613

 

2.GET方法,表單提交獲取參數

2.1 JSP表單頁面

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <script type="text/javascript" src="js/leave.js"></script>
 3 
 4 <html>
 5 <head>
 6     <title>請假審核單</title>
 7 </head>
 8 <body>
 9     <form id="leave" method="get" action="receive.jsp">
10         <!-- 請假理由 -->
11         <textarea id="reason"></textarea>
12         <input type="hidden" id="flowid" name="flowid" value="<%=flowid%>>"/>
13         <input type="button" value="審核" onclick="commit();"/>
14     </form>
15 </body>
16 </html>

2.2 接受頁面

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 2 <%@ page import="java.io.*,java.util.*" %>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="utf-8">
 7 <title>接受來自另一個JSP頁面的參數</title>
 8 </head>
 9 <body>
10 <h1>使用 GET 方法讀取數據</h1>
11 <ul>
12     <li>
13         <p><b>請假理由:</b>
14        <%= request.getParameter("reason")%>
15         </p>
16     </li>
17 </ul>
18 </body>
19 </html>    

Ps:當學習Spring后可以通過@RequestMapping更加方便的獲取傳遞過來的參數 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM