JSP中Html代码:
<body> <form action="MyJsp.jsp" method="post"> <table> <tr> <td>用户名:</td> <td><input type="text" name="name"></td> </tr> <tr> <td>密码:</td> <td><input type="password" name="pwd"></td> </tr> <tr> <td>性别:</td> <td> <input type="radio" name="sex" value="男">男 <input type="radio" name="sex" value="女">女 </td> </tr> <tr> <td>电子邮件地址:</td> <td><input type=""email name="myemail" placeholder="123456@126.com"></td> </tr> <tr> <td>出生日期:</td> <td><input type="date" name="birthday" value="1990-01-01"></td> </tr> <tr> <td>信息来源:</td> <td> <input type="checkbox" name="channel" value="报刊">报刊 <input type="checkbox" name="channel" value="网络">网络<br> <input type="checkbox" name="channel" value="电视">电视 <input type="checkbox" name="channel" value="朋友推荐">朋友推荐 </td> </tr> <tr > <td colspan="2"> <input type="submit" name="Submit" value="提交"> <input type="reset" name="Reset" value="取消"> </td> </tr> </table> </form> </body>
JSP获取内容代码:
<body> <% request.setCharacterEncoding("utf-8"); String user=request.getParameter("name"); String pwd=request.getParameter("pwd"); String sex=request.getParameter("sex"); String myemail=request.getParameter("myemail"); String birthday=request.getParameter("birthday"); %> 用户名:<%=user%><br> 密码:<%=pwd%><br> 性别:<%=sex%><br> 电子邮件地址:<%=myemail%><br> 出生日期:<%=birthday%><br> 信息来源:<% String [] information=request.getParameterValues("channel"); for(String a:information){ out.print(a+" "); } %> </body>
截图: