Servlet

08月28日(星期二)

 

Login Servlet

===================================

Login Validate

===================================

package k.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class MyLoginServletValidate extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String UserName = request.getParameter(
"txtUserName");
String UserPwd = request.getParameter("txtUserpwd");
if (UserName != null && !UserName.equals("")) {
if (UserPwd != null && !UserPwd.equals("")) {
if (UserName.equals("admin")) {
if (UserPwd.equals("123")) {
out.print("<hr><br><h1>正确登路" + UserName);
} else {
out.print("<hr><h1>密码错误!" + UserName);
}
} else {
out.print("<hr><br><h1>用户名错误!" + UserName);
}
} else {
out.println("<hr><br><h1>密码不能为空!");
}
} else {
out.println("<hr><h1>用户名不能为空!");
}
out.close();
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}
==================================

servlet

==================================

package k.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class MyLoginServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";

//Initialize global variables
public void init() throws ServletException {
System.out.println("我的程序被初始化了!");
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>MyLoginServlet</title></head>");
out.println("<body bgcolor="#ffffff">");
out.println("<form action='loginvalidate' method='post' >");
out.println("<div align='center'>");
out.println("<table width='373' height='99' border='1'>");
out.println("<tr>");
out.println("<td width='64' height='28'>用户名:</td>");
out.println("<td width='120'><input type='text' name='txtUserName'></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td height='28'>密码:</td>");
out.println("<td><input type='text' name='txtUserpwd'></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td height='33' colspan='2'>");
out.println("<input type='submit' name='Submit' value='提交'>");
out.println("<input type='reset' name='Submit' value='重置'></td>");
out.println("</tr>");
out.println("</table>");
out.println("</div>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
out.close();
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
System.out.println("我的程序被销毁了!");
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值