利用servlet和html写一个简单的登录
2015-03-13 20:28
507 查看
写一个简单的html登录页面,然后利用servlet来进行验证账号密码。
html代码:
<!DOCTYPE html>
<html>
<title>登陆页面</title>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action = "LogOnYZ" method = "post">
用户名:<input type = "text" name = "name"/>
<br>密码:<input type = "password" name = "password"/>
<br><input type = "submit" value = "登录">
</form>
</body>
</html>
这里使用doPost方法,为了安全起见。
servlet代码:
package work3;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class LogOnYZ
*/
@WebServlet("/LogOnYZ")
public class LogOnYZ extends HttpServlet {
private String User;
private String Password;
/**
* @see HttpServlet#HttpServlet()
*/
public LogOnYZ() {
super();
// TODO Auto-generated constructor stub
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html; charset = UTF-8");
PrintWriter out = response.getWriter();
User = request.getParameter("name");
Password = request.getParameter("password");
if(User.equals("abc") && Password.equals("123")){
out.print("<h1>登陆成功</h1>");
out.print("欢迎 : " + User);
}else{
out.print("<h1>账号或密码错误!</h1>");
}
out.close();
}
}
html代码:
<!DOCTYPE html>
<html>
<title>登陆页面</title>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action = "LogOnYZ" method = "post">
用户名:<input type = "text" name = "name"/>
<br>密码:<input type = "password" name = "password"/>
<br><input type = "submit" value = "登录">
</form>
</body>
</html>
这里使用doPost方法,为了安全起见。
servlet代码:
package work3;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class LogOnYZ
*/
@WebServlet("/LogOnYZ")
public class LogOnYZ extends HttpServlet {
private String User;
private String Password;
/**
* @see HttpServlet#HttpServlet()
*/
public LogOnYZ() {
super();
// TODO Auto-generated constructor stub
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html; charset = UTF-8");
PrintWriter out = response.getWriter();
User = request.getParameter("name");
Password = request.getParameter("password");
if(User.equals("abc") && Password.equals("123")){
out.print("<h1>登陆成功</h1>");
out.print("欢迎 : " + User);
}else{
out.print("<h1>账号或密码错误!</h1>");
}
out.close();
}
}
相关文章推荐
- jsp_首先利用纯HTML写一个简单的登录页面以及后台处理页面【代码】
- 一个简单的jsp+servlet实例,实现简单的登录
- 简单的一个利用MVP做的登录
- Java: 分析一个简单的配置文件并利用分析结果生成HTML文档
- 用PHP和HTML写一个简单的网站登录注册项目
- 用JSP+Servlet+JavaBean模式实现一个简单的登录网页设计(JSP+Tomcat+MySQL)
- 利用Xpath实现一个简单的登录验证程序
- 一个简单的利用微软ajax技术开发的HTMLEditer
- 利用node.js+mongodb如何搭建一个简单登录注册的功能详解
- 利用Java制作一个简单的QQ登录界面
- 一个简单的jsp+servlet实例,实现简单的登录
- 初识Jsp,JavaBean,Servlet以及一个简单mvc模式的登录界面
- Java Web 开发利用Struts2+Spring+mybatis写一个用户登录界面以及简单的数据交互
- 编写一个简单登录验证需要记录日志,Servlet中的Cookie
- HTML+Servlet + MVC + JDBC + MySQL的简单登录
- 一个简单的jsp+servlet实例,实现简单的登录
- 一个简单的jsp+servlet实例,实现简单的登录
- 一个简单的jsp+servlet实例,实现简单的登录
- 一个完整的简单jsp+servlet实例,实现简单的登录
- 一个简单的jsp+servlet实例,实现简单的登录