jsp如何做新闻发布页面_jsp和java什么关系

(46) 2024-08-15 17:01:01

JSP显示新闻

1、项目结构

java:

jsp如何做新闻发布页面_jsp和java什么关系 (https://mushiming.com/)  第1张

Web:

jsp如何做新闻发布页面_jsp和java什么关系 (https://mushiming.com/)  第2张

2、Java部分详细介绍

2.1 Controller

jsp如何做新闻发布页面_jsp和java什么关系 (https://mushiming.com/)  第3张

LoginServlet:

用来获取网站的登录信息,并传给UsersService进行处理判断

1 packageController;2

3 importEntity.Users;4 importService.UsersService;5 importUtil.CookieSave;6 importjavax.servlet.ServletException;7 importjavax.servlet.annotation.WebServlet;8 importjavax.servlet.http.HttpServlet;9 importjavax.servlet.http.HttpServletRequest;10 importjavax.servlet.http.HttpServletResponse;11 importjava.io.IOException;12 importjava.sql.SQLException;13

14 @WebServlet(name = "Controller.LoginServlet")15 public class LoginServlet extendsHttpServlet {16 protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsIOException, ServletException {17 doGet(request,response);18 }19 protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {20 response.setContentType("text/html;charset=utf-8");21 request.setCharacterEncoding("utf-8");22 //Login的处理

23 try{24 Login(request,response);25 } catch(SQLException e) {26 e.printStackTrace();27 }28 }29 void Login(HttpServletRequest request, HttpServletResponse response) throwsIOException, SQLException {30 //获取表单中的数据的值

31 Users user=newUsers();32 user.setName(request.getParameter("username"));33 user.setPassword(request.getParameter("password"));34 System.out.println("登入用户名:"+user.getName());35 System.out.println("登入用户密码:"+user.getPassword());36 System.out.println("-------------------------------");37 //验证用户名密码

38 UsersService usersService=newUsersService();39 boolean hasUsers=usersService.QueryUsers(user);40 if(hasUsers){41 CookieSave cookieSave=newCookieSave();42 cookieSave.Save(response,"username",user.getName(),60*60*24*30);43 cookieSave.Save(response,"password",user.getPassword(),60*60*24*30);44 //成功登录

THE END

发表回复