jsp:提交表单在另一个页面获取request中的信息

jsp:提交表单在另一个页面获取request中的信息

想看目录,用到了login2.jsp和index.jsp
在这里插入图片描述
login2.jsp
在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<form action="index.jsp" method="Get">
        <table>
            <tr>
                <td>用户名: </td>
                <td><input type="text" name="user"></td>
            </tr>
            <tr>
                <td>密    码: </td>
                <td><input type="password" name="pwd"></td>
            </tr>
            <tr>
                <td>性    别:</td>
                <td>
                    <input type="radio" checked="checked" name="sex" value="male"><input type="radio"  name="sex" value="female"></td>
            </tr>
            <tr>
                <td>爱    好:</td>
                <td><input type="checkbox" value="1" name="hoppy">唱歌
                <input type="checkbox" value="2" name="hoppy">跑步
                <input type="checkbox" value="3" name="hoppy">读书
                <input type="checkbox" value="2" name="hoppy">蹦迪</td>
            </tr>
        </table>
        <input type="submit" value="提交">
    </form>
</body>
</html>

index.jsp
在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%	
	request.setCharacterEncoding("utf-8");
	//用户名
	String name=request.getParameter("user");
	//获取密码
	String pwd=request.getParameter("pwd");
	//获取性别
	String sex=request.getParameter("sex");
	//获取爱好(数组类型
	String hoppy[]=request.getParameterValues("hoppy");
	
%>
	<table>
		<tr>
			<td>姓名:</td>
			<td><%out.print(name); %></td>
		</tr>
		<tr>
			<td>密码:</td>
			<td><%out.print(pwd); %></td>
		</tr>
		<tr>
			<td>性别:</td>
			<td><%out.print(sex); %></td>
		</tr>
		<tr>
			<td>爱好:</td>
			<td><%for(int i=0;i<hoppy.length;i++){
    
    
				out.print(hoppy[i]);
			} %></td>
		</tr>
	
	</table>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/a1424261303/article/details/114601812
今日推荐