看的韩的视频
基本写的都一样,从登录//Login,到验证//LoginCl,成功//Wel
- Java code
package com.zgd;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class Login extends HttpServlet {
// get
public void doGet(HttpServletRequest req,HttpServletResponse res){
System.out.println(" service ");
res.setContentType("text/html; charset=gbk");
try {
PrintWriter pw=res.getWriter();
pw.println(" <html>");
pw.println(" <title>");
pw.println("学生登录");
pw.println(" </title>");
pw.println(" <body>");
pw.println(" <H1>登录界面 </H1>");
pw.println(" <form action=LoginCl,method=post>");
pw.println("用户名: <input type=text name=username> <br>");
pw.println("密码: <input type=password name=passwd> <br>");
pw.println(" <input type=submit value=Login> <br> ");
pw.println(" </form>");
pw.println(" </body>");
pw.println(" </html>");
}
catch(Exception e){
e.printStackTrace();
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res){
doGet(req,res);
}
}
- Java code
package com.zgd;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class LoginCl extends HttpServlet {
// get
public void doGet(HttpServletRequest req,HttpServletResponse res){
res.setContentType("text/html; charset=gbk");
try {
PrintWriter pw=res.getWriter();
pw.println(" <html> <body> <h1>你来到了 验证界面 </h1> </body> </html>");
String u=req.getParameter("username");
String p=req.getParameter("passwd");
if(u.equals("xll")&&p.equals("xll")){
res.sendRedirect("Wel");
} else {
res.sendRedirect("Login");//to URL
}
}
catch(Exception e){
e.printStackTrace();
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res){
this.doGet(req,res);
}
}
- Java code
package com.zgd;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class Wel extends HttpServlet {
// get
public void doGet(HttpServletRequest req,HttpServletResponse res){
System.out.println(" service ");
try {
PrintWriter pw=res.getWriter();
pw.println("WEL COME ,U");
}
catch(Exception e){
e.printStackTrace();
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res){
doGet(req,res);
}
}
web-xml
- XML code