webDemo.zip
立即下载
资源介绍:
webDemo.zip
package com.ww.web_demo.servlet;
import com.ww.web_demo.javabean.Student;
import com.ww.web_demo.service.IStudentService;
import com.ww.web_demo.service.impl.StudentServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
private IStudentService iStudentService=new StudentServiceImpl();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//第一步:接收输入的用户名和密码
String username=req.getParameter("username");//接收form表单里面带入的参数
String password=req.getParameter("password");
//第二步:判断用户名和密码是否存在,存在,登录成功,不存在,登录失败
if("admin".equals(username)&&"admin".equals(password)){
List list=iStudentService.findAll();
req.setAttribute("list",list);
req.getRequestDispatcher("main.jsp").forward(req,resp);
// resp.sendRedirect("main.jsp");
}else{
resp.sendRedirect("index.jsp");
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
//public class LoginServlet implements Servlet {
// @Override
// public void init(ServletConfig servletConfig) throws ServletException {
//
// }
//
// @Override
// public ServletConfig getServletConfig() {
// return null;
// }
//
// @Override
// public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
// //第一步:接收输入的用户名和密码
// String username=servletRequest.getParameter("username");//接收form表单里面带入的参数
// String password=servletRequest.getParameter("password");
// //第二步:判断用户名和密码是否存在,存在,登录成功,不存在,登录失败
// if("admin".equals(username)&&"admin".equals(password)){
// PrintWriter pw=servletResponse.getWriter();
// pw.write("学生信息管理系统");
// }else{
// PrintWriter pw=servletResponse.getWriter();
// pw.write("没有找到该用户");
// }
//
// }
//
// @Override
// public String getServletInfo() {
// return null;
// }
//
// @Override
// public void destroy() {
//
// }
//}
资源文件列表:
webDemo.zip 大约有198个文件