Wrox Programmer Forums
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2007, 12:11 AM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Servlet Problem

Hi there

I am having a problem. Can anyone please help me.

I wrote a simple JSP with user name and Password --->

 <%
      String booknull = (String) request.getAttribute("wrongentry");
 %>
<html>
  <head>
      <title>Login Screen</title>
       <link rel="stylesheet" type="text/css" href=".\..\css\webapp.css">
  </head>
  <body>
    <form name="login" method="get" action="./checklogin.servlet">
        <table class="dosizing">
      <% if((booknull != null) && (booknull.equals("false"))) { %>
      <tr>
         <td colspan="2" class="doalign">Invalid Store Name or Password</td>
      </tr>
     <% } %>
          <tr>
         <td colspan="2" class="doalign">Please enter your User Id and password below..</td>
      </tr>
      <tr class="dopad">
        <td class="dodistance1">User Id:</td>
        <td class="dodistance1"><input type ="text" id="userid" name="userid"
              size="40" maxlength="40"/></td>
      </tr>
      <tr>
        <td class="dopad">Password:</td>
        <td class="dopad"><input type ="password" id="password" name="password"
              size="40" maxlength="40"/></td>
      </tr>
      <tr>
        <td></td>
        <td class="dodistance"><input type="submit" value ="Log in">
      </tr>
    </table>
     </form>
 </body>
</html>

web.xml --->

<web-app>
 <servlet>
    <servlet-name>checklogin</servlet-name>
    <servlet-class>com.titanamericas.servlets.CheckLogin</servlet-class>
  </servlet>
<servlet-mapping>
    <servlet-name>checklogin</servlet-name>
    <url-pattern>/checklogin.servlet</url-pattern>
  </servlet-mapping>

</web-app>

Servlet --->
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
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 com.mysql.jdbc.Connection;

public class CheckLogin extends HttpServlet {

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        System.out.println("Print 0");
        ServletContext context = getServletContext();
        HttpSession session = request.getSession();
        System.out.println("Print 1");
        String name = (String) request.getParameter("name");
        String password = (String) request.getParameter("password");
        System.out.println("Name Password " + name + " " + password);
        //session.setAttribute("name", name);
        //session.setAttribute("password", password);
        System.out.println("Print 2");

            // calling BookstoreBean.getStore()
            BookstoreBean bb = new BookstoreBean();
            System.out.println("Print 4");
            //BookstoreBean ibook = bb.getStore(conn, name, password);
            String ibook = null;
            if (ibook == null) {
                request.setAttribute("wrongentry", "false");
                System.out.println("Print 5");
                RequestDispatcher disp = request
                        .getRequestDispatcher("login.jsp");
                if (disp != null)
                    disp.forward(request, response);
            } else {
                request.setAttribute("wrongentry", "true");
                session.setAttribute("bookstore", ibook);
                RequestDispatcher disp = request
                        .getRequestDispatcher("/books2.servlet");
                if (disp != null)
                    disp.forward(request, response);
            }
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        doPost(request, response);
    }


I am trying to get this Servlet. I have printed like Print 0, Print 1 but in url I am getting ...localhost../app/jsp/checklogin.servlet?userid=1&password=1

But its showing HTTP Status 404 app/jsp/checklogin.servlet not found.

Anything that I am missing? Its not printing anything in the console that means its not going upto servlet. But JSP is good.. Because I am getting the page with value in the URL. So class path is set properly I think.


 
Old April 23rd, 2007, 11:14 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

If you see the <url-pattern> tag in the web.xml its give like /checklogin.servlet, which means the servlet is supposed be called when the browser hits the url http://localhost:8080/yourapplicatio...klogin.servlet.

But the url you've mentioned is like http://localhost:8080/app/jsp/checklogin.servlet which means the action attribute is not set correctly.
If you see the <form> tag you've mentiond action="./checklogin.servlet" which is wrong, instead use action="<%= request.getContextPath()+"/"%>checklogin.servlet"

Hope its clear to you.

Regards,
Rakesh
 
Old April 28th, 2007, 09:39 AM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks Rakesh. Its working






Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with servlet developer.ibm Servlets 1 September 12th, 2007 11:22 PM
My servlet problem saeed Servlets 1 April 10th, 2007 07:12 AM
servlet Problem discuss Servlets 3 February 6th, 2007 02:06 PM
servlet problem discuss Servlets 1 August 29th, 2006 10:03 AM
Servlet problem Ravi Kumar Servlets 1 June 20th, 2005 04:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.