處理方法:
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>