处理方法:
1、登录 按钮通过表单<form>
标签里的action属性跳转到Servlet后台
2、注册 按钮通过 超链接<a>
标签跳转到另一个页面
补充:
action这里可以带上参数:action="Servlet?method=login"
这一句代码的意思是带上method的值跳转传到到Servlet后台,后台取method值的代码是:String method = request.getParameter("method");
直接上JSP页面的代码吧:
<%@ page language="java" import="java.util.*"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.text.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录界面</title>
<style type="text/css">
* {
margin: 5px;
}
</style>
</head>
<body>
<form name="myform" action="Servlet?method=login" method="POST">
用户名<input type="text" name="username" /><br>
密 码<input type="password" name="pwd" /><br>
<input type="submit" value=" 登录 " /> <a href="register.jsp"><input
type="button" value=" 注册 "></a> <span style="color: red"><%=request.getAttribute("msg") == null ? "" : request.getAttribute("msg")%></span>
</form>
</body>
</html>