工具:MyEclipse2014+Tomcat7
1、建立Web工程
工程名为:RegisterSystem
2、在WebRoot目录下编写login.jsp
3、在src文件夹下创建com.ht.servlet包并编写Account.java
package com.ht.servlet;
public class Account {
//账户用户名与密码
private String username="";
private String password="";
public String getUsername(){
return this.username;
}
public void setUsername(String username){
this.username=username;
}
public void setPassword(String password){
this.password=password;
}
}
4、在com.ht.servlet包下编写CheckAccount.java
package com.ht.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class CheckAccount extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
protected void doPos(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
doGet(request,response);
}
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
HttpSession session = request.getSession();
Account acct = new Account();
String username = request.getParameter("username");
String password = request.getParameter("password");
acct.setUsername(username);
acct.setPassword(password);
if((username != null)&&(username.trim().equals("jsp"))){
if((password != null)&&(password.trim().equals("1"))){
System.out.println("Success");
session.setAttribute("account", acct);
String login_success = "success.jsp";
response.sendRedirect(login_success);
return;
}
}
String fail_login="fail.jsp";
response.sendRedirect(fail_login);
return;
}
}
5、在WebRoot目录下编写success.jsp
7.在WebRoot目录下编写fail.jsp
8.修改Web配置文件
9.使用Tomcat7运行Web工程
10.在Tomcat安装位置上可以发现我们工程文件的内容
11、使用浏览器打开页面