输入用户名和密码的界面:
<%@ page language="java" contentType="text/html;charset=gb2312" %> <script type="text/javascript"> function on_submit() { if(form1.username.value=="") { alert("用户名不能为空!"); // 自动把焦点切换到username的输入框 form1.username.focus(); return false; } if(form1.password.value=="") { alert("密码不能为空!"); // 自动把焦点切换到password的输入框 form1.password.focus(); return false; } } </script> <html> <head> <title>请求表单</title> </head> <body> <form action="acceptform.jsp" method="post" name="form1" onsubmit="return on_submit()"> <table style="margin:auto ;margin-top:200px" > <tr> <td colspan="2" align="center">请输入数据:</td> </tr> <tr> <td>用户名:</td> <td><input type="text" name="username"></td> </tr> <tr> <td>密码:</td> <td><input type="password" name="password"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="提交"></td> </tr> </table> </form> </body> </html>
显示接收到的表单中的数据:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>接收表单数据</title> </head> <body> 接收到的用户名:${param.username }<br> 接收到的密码:${param.password } </body> </html>
JSP简单练习-EL获取表单数据
时间: 2024-10-15 03:46:31