| |

VerySource

 Forgot password?
 Register
Search
View: 803|Reply: 4

How to debug servlet in eclipse?

[Copy link]

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-9-28 22:00:01
| Show all posts |Read mode
//////////Log in 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">Yuanmeng IT Book Ordering Net</h1>
    </div></td>
  </tr>
  <tr>
    <td width="325">&nbsp;</td>
    <td width="131"><div align="center">User name: </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">Secret code:</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="log in" />
       &nbsp;&nbsp;&nbsp;
<input name="guest" type="submit" value="Guest">
<span class="STYLE3">[Note:] Logging in as the default guest will not be eligible for membership discounts</span> </p>
</td>
    <td>&nbsp;</td>
To
  </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 {
To
String pass=null, uname=null;

// Get the HttpSession object.
HttpSession session = req.getSession();
To
// 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);
}
To
// Get the username and password parameters.
pass = req.getParameter("password");
uname = req.getParameter("username");
To
// Invalidate the session to get rid of any old Member or Librarian objects.
session.invalidate();
To
// Get a fresh session.
session = req.getSession();
To
// Create a new library member through validation. If the uname is not valid, the member is null.
Member member = null;
To
try {
String ssn=(String)session.getAttribute("username");
String passWord=(String)session.getAttribute("password");
String sql = "SELECT * FROM Member WHERE ID = "+ ssn +
"AND password ='" + passWord + "'";
To
ResultSet r = db.runQuery(sql);
To
//member = db.validateMember( uname, pass );
/*} catch( Exception e ){
}
To
try {*/
// The member is not null, so he must have been validated. Place the member into the session.
if (r!=null) {
To
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.
To
}
    }
}


After clicking login, I link to http://localhost:8090/MyBookStore/MemberLoginController to find the servlet but why is it blank? How to debug?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-9-28 23:30:01
| Show all posts
res.sendRedirect("/MyBookStore/LoginError.jsp");

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


It is the problem of the path of these two sentences!!!!!
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-9-29 06:00:01
| Show all posts
Jetty&JettyLaucher Eclipse Plugin
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-9-29 07:00:01
| Show all posts
No problem, if the path to pick is http://localhost:8090/MyBookStore/LoginError.jsp? What
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-9-29 11:30:05
| Show all posts
res.sendRedirect("/MyBookStore/LoginError.jsp");

res.sendRedirect("/MyBookStore/index.jsp");////Change to
res.sendRedirect("LoginError.jsp");

res.sendRedirect("index.jsp");////
Still nothing is displayed
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list