简单的登录界面
-------------------------------------------------------------------------------------------------
//登录界面
package com.fuying;
import javax.servlet.http.*;
import java.io.*;
public class Login extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try {
//中文乱码
res.setContentType("text/html;charset=gbk");
PrintWriter pw = res.getWriter();
//返回登录界面
pw.println("<html>");
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=loing><br>");
pw.println("</form>");
pw.println("</body>");
pw.println("</html>");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
{
this.doGet(req,res);
}
}
--------------------------------------------------------------------------------------------------
//处理界面
package com.fuying;
import javax.servlet.http.*;
import java.io.*;
public class LoginCl extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try {
//接收用户名密码
String u=req.getParameter("username");
String p=req.getParameter("passwd");
if(u.equals("fy")&&p.equals("123"))
{//合法用户
//跳转到欢迎界面
res.sendRedirect("welcome");
}
else
{//不合法.跳转到Login页面。跳转写url。
res.sendRedirect("login");
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
{
this.doGet(req,res);
}
}
--------------------------------------------------------------------------------------------------
//欢迎界面
package com.fuying;
import javax.servlet.http.*;
import java.io.*;
public class Welcome extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try {
res.setContentType("text/html;charset=gbk");
PrintWriter pw = res.getWriter();
pw.println("欢迎登录");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
{
this.doGet(req,res);
}
}