VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 811|回复: 4

eclipse中servlet怎么调试?

[复制链接]

1

主题

7

帖子

6.00

积分

新手上路

Rank: 1

积分
6.00
发表于 2020-9-28 22:00:01 | 显示全部楼层 |阅读模式
//////////登陆jsp///////////////////////////////////////////////
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="MyBookStore.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<link rel="stylesheet" type="text/css" href="MyBookStore/styles.css">
<style type="text/css">
<!--
.STYLE1 {color: #663333}
.STYLE3 {font-size: 12px}
-->
</style>
<!-- Copyright 2000,2001,2002 Macromedia, Inc. All rights reserved. -->
</head>

<body>

<table width="978" height="300" border="1" align="left">
<form method="post" action="MemberLoginController">
  <tr>
    <td colspan="4"><div align="center">
      <h1 class="STYLE1">缘梦IT图书定购网</h1>
    </div></td>
  </tr>
  <tr>
    <td width="325">&nbsp;</td>
    <td width="131"><div align="center">用户名: </div></td>
    <td width="297">&nbsp;
    <input name="username" type="text" value="guest" size="20" maxlength="20"></td>
    <td width="197">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><div align="center">密 码:</div></td>
    <td>&nbsp;
        <input name="password" type="password" value="12345" size="20" maxlength="20">    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2">
      <p>
        <input name="enter" type="submit" value="登陆" />   
        &nbsp;&nbsp;&nbsp;
                <input name="guest" type="submit" value="游客">
                <span class="STYLE3">[注:]以默认的guest身份登陆将不能享受会员折扣</span>          </p>
        </td>
    <td>&nbsp;</td>
       
  </tr>
  </form>
</table>

</body>
</html>

////////////////////////////////servlet///////////////////////////////////
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import MyBookStore.DBWrapper;
import MyBookStore.Member;

/**
* Class <b>MemberLoginController</b> contains
* the servlet controller functionality for processing
* member login requests.
*
*
* @author CTE
* @version 1.0
*/
public class MemberLoginController extends HttpServlet {

    /**
     * MemberLoginController doPost method.  This is can be called
     * by <b>Controller</b> superclass' doGet() method.
     * @param req HttpServletRequest servlet request object
     * @param res HttpServletResponse servlet response object
     * @throws ServletException
     * @throws IOException
     */
    public void doPost (HttpServletRequest req,
                        HttpServletResponse res) throws ServletException, IOException {
       
        String pass=null, uname=null;

        // Get the HttpSession object.
        HttpSession session = req.getSession();
       
        // Create a Library object instance.
        DBWrapper db = null;

        // Create a new instance of the Library object.
        try {
            db=DBWrapper.Instance();
        } catch( Exception e ) {
           // sendErrorRedirect(req, res, e);
        }
       
        // Get the username and password parameters.
        pass = req.getParameter("password");
        uname = req.getParameter("username");
       
        // Invalidate the session to get rid of any old Member or Librarian objects.
        session.invalidate();
       
        // Get a fresh session.
        session = req.getSession();
       
        // Create a new library member through validation.  If the uname is not valid, the member is null.
        Member member = null;
       
        try {
                String ssn=(String)session.getAttribute("username");
                String passWord=(String)session.getAttribute("password");
                String sql = "SELECT * FROM Member WHERE ID = " + ssn +
            " AND password = '" + passWord + "'";
       
            ResultSet r = db.runQuery(sql);
       
            //member = db.validateMember( uname, pass );
        /*} catch( Exception e ){
                    }
       
        try {*/
            // The member is not null, so he must have been validated.  Place the member into the session.
            if (r!=null) {
                   
            String idname=r.getString("memberID");
            int discount=r.getInt("discount");
            member=new Member(idname,discount);
                session.setAttribute("member", member);
                res.sendRedirect("/MyBookStore/index.jsp");////
            } else {
                /**
                 * The member was not validated.  We simply
                 * set an error message, and redirect back to
                 * the member login page.
                 */
                res.sendRedirect("/MyBookStore/LoginError.jsp");
            }
        } catch (Exception e2) {
            // Something bad happened, so redirect to the error page.
            
        }
    }
}


点击登陆后,链接到了 http://localhost:8090/MyBookStore/MemberLoginController找到servlet但是为什么是空白呢?请问怎么调试?
   


回复

使用道具 举报

0

主题

2

帖子

3.00

积分

新手上路

Rank: 1

积分
3.00
发表于 2020-9-28 23:30:01 | 显示全部楼层
res.sendRedirect("/MyBookStore/LoginError.jsp");

res.sendRedirect("/MyBookStore/index.jsp");////


是这两句的路径的问题吧!!!!!
回复

使用道具 举报

0

主题

39

帖子

23.00

积分

新手上路

Rank: 1

积分
23.00
发表于 2020-9-29 06:00:01 | 显示全部楼层
Jetty & JettyLaucher Eclipse Plugin
回复

使用道具 举报

1

主题

7

帖子

6.00

积分

新手上路

Rank: 1

积分
6.00
 楼主| 发表于 2020-9-29 07:00:01 | 显示全部楼层
没问题啊,难道挑转的路径要是http://localhost:8090/MyBookStore/LoginError.jsp?么
回复

使用道具 举报

1

主题

7

帖子

6.00

积分

新手上路

Rank: 1

积分
6.00
 楼主| 发表于 2020-9-29 11:30:05 | 显示全部楼层
res.sendRedirect("/MyBookStore/LoginError.jsp");

res.sendRedirect("/MyBookStore/index.jsp");////改为
res.sendRedirect(“LoginError.jsp");

res.sendRedirect("index.jsp");////
仍然什么都不显示阿
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表