图书管理系统的设计与开发(7)

2019-03-11 14:17

登录后主页面

示例代码如下所示:

1)注册代码:package servlet;

import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException;

import javax.servlet.ServletException; import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

import bean.userBean;

import dao.user;

31

public class ZhuceServlet extends HttpServlet {

/**

* Constructor of the object. */

public ZhuceServlet() { super(); }

/**

* Destruction of the servlet.
*/

public void destroy() {

super.destroy(); // Just puts \ // Put your code here }

/**

* The doGet method of the servlet.
*

* 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 { }

/**

* The doPost method of the servlet.
*

* 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 {

32

String name=request.getParameter(\ String pwd=request.getParameter(\ user test=new user(); try {

userBean user=test.check(name); if(user==null){

userBean user1=new userBean(name,pwd); test.register(user1); response.sendRedirect(\ }else{

response.sendRedirect(\ }

} catch (Exception e) {

// TODO Auto-generated catch block e.printStackTrace(); }

}

/**

* Initialization of the servlet.
*

* @throws ServletException if an error occurs */

public void init() throws ServletException { // Put your code here } }

2)登陆代码: package servlet;

import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.List;

import javax.servlet.ServletException; import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

import dao.library; import dao.user;

import bean.libraryBean;

33

import bean.userBean;

public class LoginServlet extends HttpServlet {

/** * */

private static final long serialVersionUID = 1L;

/**

* Constructor of the object. */

public LoginServlet() { super(); }

/**

* Destruction of the servlet.
*/

public void destroy() {

super.destroy(); // Just puts \ // Put your code here }

/**

* The doGet method of the servlet.
*

* 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(\ String name=request.getParameter(\ String pwd=request.getParameter(\ //userBean user = new userBean(name,pwd); user test=new user(); try {

userBean user = test.check(name); if (user!=null){

34

if (pwd.equals(user.getPWD())){

library bookinfo=new library();//Dao涓?殑library List list=bookinfo.selectall(); request.getSession().setAttribute(\

// response.sendRedirect(request.getContextPath() + \

request.getRequestDispatcher(\ }else{

response.sendRedirect(\ } }else{

response.sendRedirect(\ } } catch (Exception e) {

// TODO Auto-generated catch block e.printStackTrace(); } }

/**

* The doPost method of the servlet.
*

* 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(\ doGet(request,response); }

/**

* Initialization of the servlet.
*

* @throws ServletException if an error occurs */

public void init() throws ServletException { // Put your code here } }

35


图书管理系统的设计与开发(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:中国传统文化及其当代价值

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: