LoginServlet.java
package com.sevend.view;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
//告诉浏览器以utf-8去解析(浏览器的默认编码就会成utf-8)
response.setCharacterEncoding("utf-8");
//设置编码方式两者都是同一个作用,配合使用更好
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("<HEAD><TITLE>用户登陆界面</TITLE></HEAD>");
out.println("<BODY>");
out.println("<h1>用户登陆</h1>");
//action路径规范:/web应用名/servlet的url
out.println("<form action='/UserManage/servlet/LoginCLServlet' method='post'>");
out.println("用户名:<input type='text' name='username' id='username' /><br/>");
out.println("密 码:<input type='password' name='password' id='password' /><br/>");
out.println("<input type='submit' value='登陆' /><br/>");
out.println("</form>");
out.println("</BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
LoginCLServlet.java
package com.sevend.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class LoginCLServlet extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
@SuppressWarnings("unused")
PrintWriter out = response.getWriter();
//接受用户提交的用户名和密码
String username=request.getParameter("username");
String password=request.getParameter("password");
//验证一下时候能够接受数据
// System.out.println("username="+username+"password="+password);
if("sevend".equals(username)&&"123".equals(password)){
//跳转到下一个页面,servlet提供了两种方法:
//一:sendredirect转向
//sendredirect的url格式/web应用名称/servlet url
response.sendRedirect("/UserManage/servlet/MainFrame");
//二:forward转发
}else{
response.sendRedirect("/UserManage/servlet/LoginServlet");
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
@SuppressWarnings("unused")
PrintWriter out = response.getWriter();
this.doGet(request, response);
}
}
MainFrame.java
package com.sevend.view;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class MainFrame extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print("MainFrame");
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
@SuppressWarnings("unused")
PrintWriter out = response.getWriter();
this.doGet(request, response);
}
}
分享到:
相关推荐
包含增删查改四项功能的Servlet项目
本项目是一套基于Servlet+Jsp实现的酒店客房预定管理系统分前后台,主要针对计算机相关专业的正在做bishe的学生和需要项目实战练习的Java学习者。 包含:项目源码、数据库脚本等,该项目可以直接作为bishe使用。 ...
旅游网站旅游管理系统,java项目, servlet ,jsp web项目。eclipse和idea都能打开运行。 主要用于实现旅游景点信息管理,基本功能包括:主界面模块设计,用户注册模块,旅游景点模块,酒店预订模块,后台管理模块等...
项目主要包括管理员与用户两种角色; 管理员角色包含以下功能:管理员登录,主页面,分类查看,修改个人信息,上传小说,查看小说,删除小说,评论顶收藏小说等功能。 用户角色包含以下功能:用户注册,用户登录,查看销售,...
本项目分为前后台,分为管理员与普通用户两种角色,管理员登录后台,普通用户登录前台; 管理员角色包含以下功能: 管理员登录,修改个人信息,报名管理,游客管理,活动管理,活动类型管理等功能。 用户角色包含以下...
实现的功能:客房,楼层,商品类别,商品,会员的增删改查,预定信息的增删,预定转入住,换房管理,结账管理,直接入住管理,用户管理,日志的查询,预定客人报表,在住客人报表,离店客人报表。 特点:以上功能...
标题:全面人事管理系统Java源码web项目,技术栈,实现高效企业运营! 描述: 您正在寻找一款高品质的企业员工人事管理系统源码吗?不用再寻找了!我推出基于Java Servlet和MySQL开发的企业员工人事管理系统,满足...
项目不是很大,但做期末考试绰绰有余,而且适合初学者,里面用到的技术都是内容,没有超纲,而且简单通俗易懂,是初学者的一道福音,不难而且五脏俱全! 用到的技术:jsp、javabean、servlet、mysql 用到的开发工具...
本项目是一套基于servlet和jsp实现的学生信息管理系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者。 包含:项目源码、项目文档、数据库脚本、软件工具等,该项目附带全部源码可作为...
项目名称:基于JSP+Servlet的户籍管理系统 用户类型:双角色(普通用户、管理员) 项目架构:B/S架构 设计思想:MVC 开发语言:Java语言 前端技术:Layui、HTML、CSS、JS、JQuery等技术 后端技术:JSP、Servlet、C3P...
这是一个基于jsp+servlet的web项目,没有用到框架技术,主题是客户资源管理系统,有名片信息管理、客户信息管理、组信息管理、用户信息管理、同一人物设定,管理员专区等模块,其中包括图片上传,文件上传、权限控制...
该项目未使用spring框架,实现了用户登录,权限控制,数据统计,以及市场活动、线索、客户、联系人、合同的CRUD,使用Proxy实现Service层的动态代理,实现DAO层事务控制,有助于深入理解web项目 运行环境 jdk8+...
当前各类数据库内容提供商针对零散用户抱怨数据库内容收费太高的情况,推出了一种以浏览文章扣除相应金额的推销方式,该方式吸引了许多仅浏览少量收费信息的用户,扩充了内容...压缩文件里有项目实现的基本功能word文档
sp网上酒店管理系统,ssh项目,网上酒店管理系统,酒店管理系统,java项目 网上酒店管理系统 主要面向酒店开发和使用: 系统使用JSP+Servlet+JDBC技术开发。 系统角色分为:经理(管理员)和员工(普通用户)两种用户,...
人力资源管理系统,主要有招聘管理,培训管理,薪金管理和用户管理。 运行环境 jdk8+tomcat8+mysql+eclipse 项目技术(必填) Jsp+ java Servlet+DButils+c3p0连接池+mysql 运行视频(可选) 链接:...
基于Servlet+JSP的智能小区物业管理系统源码.zip 完整代码,可运行 项目描述 用户登录管理,通过它可以对登录信息进行管理。实现对进入系统的人员进行分类管理,实现不同身份的用户能够获得相应功能的使用权限。 ...
这是一个纯JavaWeb项目,采用MVC模式,即 模型(model)-视图(view)-控制器(controller),没有使用其他框架,采用的是纯servlet+jsp实现的一个简易选课JavaWeb项目,实现的功能如下:包括 **管理员 教师 学生** ...
本项目是基于J2EE的Servlet的在线蛋糕店管理系统,本项目有三种权限:游客、用户、管理员。 游客:浏览查看商品、注册登录 用户:浏览查看商品、加入购物车、我的订单、结算订单 管理员:管理员管理、用户管理、商品...
本文基于JAVA,JSP,SERVLET,MYSQL技术进行酒店客房管理, 酒店客房功能分为前台和后台, 前台功能包含:首页, 用户注册,用户中心,客房搜索,预定记录,在线留言,后台功能包含:住宿管理,客房管理,客房类型管理,会员...
基于jsp+servlet的机票预订后台管理系统源码+项目说明(前端 jsp、jquery,后端 servlet、jdbc,角色分为管理员、用户;集成航班信息查询,在线订票,订单查询等功能于一体的系统).zip 基于jsp+servlet的机票预订...