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更加方便的获取传递过来的参数