Results 1 to 8 of 8
  1. #1
    proksy is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Question web.xml servlet mapping not directing to servlet

    Hi everyone. I am going through a login example which can be found here: JSP - Servlets: Full Login Example I created a simple main runner class to make sure I can connect to the database and all is good. The problem I am having is configuring my web.xml file to point to my LoginServlet file. I have tried more simple servlet tutorials and get them to work but I am hitting a wall on this one and was wondering if someone could give me a push in the right direction. I am able to navigate to my LoginPage.jsp file but when I hit the submit button I get the ol' apache tomcat 404 error: "The requested resource(/LoginServlet) is not available."

    Here is the contents of my web.xml file:

    Java Code:
    <web-app>
      <servlet>
        <servlet-name>LoginServlet</servlet-name>
        <servlet-class>ExamplePackage.LoginServlet</servlet-class>
      </servlet>
      
      <servlet-mapping>
        <servlet-name>LoginServlet</servlet-name>
        <url-pattern>/LoginPage</url-pattern>
        <url-pattern>/UserLogged</url-pattern>
        <url-pattern>/InvalidLogin</url-pattern>
      </servlet-mapping>
    </web-app>
    I'm deffinately doing something wrong with this. Thanks for the help!
    Last edited by proksy; 06-11-2012 at 02:35 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: web.xml servlet mapping not directing to servlet

    What are you putting into the browser for a URL?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    proksy is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: web.xml servlet mapping not directing to servlet

    sorry everyone I've been swamped with work for a new job and have been out of state for a while and now I'm back....here is what I put into the url --> localhost/LoginPage.jsp and it loads just fine but when I hit submit it then gives me the 404 error

    I know the tutorial had me create a folder named LoginExample but when I navigated to --> localhost/LoginExample/LoginPage.jsp and clicked submit I got the same error so I tried moving it to my ROOT folder. In hindsight it seems pointless and noobish to do that...anyways, when I navigate to LoginPage.jsp it loads correctly but when I click the submit button I recieve the 404 error..thanks Tolls
    Last edited by proksy; 06-21-2012 at 06:39 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: web.xml servlet mapping not directing to servlet

    So it's not that JSP causing the problem then, but whatever thje submit is referencing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: web.xml servlet mapping not directing to servlet

    The error said that it cannot find a resource named "/LoginServlet". I saw that you have a servlet called LoginServlet, but this servlet is not mapped to the url pattern of "/LoginServlet". Instead this servlet was registered to be accessed with a url pattern such as "/LoginPage", "/UserLogged", or "/InvalidLogin".

    This mean you should change the action attribute of your login page to point one of this registered url pattern to access the LoginServlet.

  6. #6
    proksy is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: web.xml servlet mapping not directing to servlet

    I've reworked the tutorial again and realized I goofed up. Here is what I have in my web.xml file

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	<display-name>LoginExample</display-name>
    	<servlet>
    		<description>
    		</description>
    		<display-name>LoginServlet</display-name>
    		<servlet-name>LoginServlet</servlet-name>
    		<servlet-class>
    		ExamplePackage.LoginServlet</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>LoginServlet</servlet-name>
    		<url-pattern>/LoginServlet</url-pattern>
    	</servlet-mapping>
    	<welcome-file-list>
    		<welcome-file>LoginPage.jsp</welcome-file>
    	</welcome-file-list>
    </web-app>
    This is what I have in my action for my form or button

    Java Code:
    <%@ page language="java" contentType="text/html;
     charset=windows-1256" pageEncoding="windows-1256" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    	<head> 
    		<meta http-equiv="Content-Type" content="text/html;
     		charset=windows-1256"> 
    		<title>Login Page</title> 
    	</head> 
    	<body> 
    		<form action="LoginServlet"> 
    			Please enter your username <input type="text" name="un"/><br> 				
    			Please enter your password <input type="text" name="pw"/> 
    			<input type="submit" value="submit"> 
    		</form> 
    	</body> 
    </html>
    Sense I'm not calling anything I didn't think I needed an import statement...seems like I have it right now but I still get the 404 error for some reason. I've got a Java EE book coming to me so that should help me figure this stuff out too. My form action="LoginServlet" seems to be where the problem lies. I think you all are right. Thanks for the help!

  7. #7
    proksy is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: web.xml servlet mapping not directing to servlet

    Java Web Programming with Eclipse this online book got me going. I honestly don't like IDE templates like the ones eclipse uses because if I follow a tutorial that relies heavily on them, I don't get to know how EVERYTHING works. Thanks for the input and the help. My problem seems to be solved ;) Highly recommend this free online book.

  8. #8
    gowthamgutha is offline Member
    Join Date
    Sep 2012
    Location
    Guntur, India
    Posts
    27
    Rep Power
    0

    Default Re: web.xml servlet mapping not directing to servlet

    You are handling multiple url patterns in the same servlet class, i think that could not be possible!

Similar Threads

  1. Servlet Mapping question.
    By Mega Man X in forum Java Servlet
    Replies: 2
    Last Post: 02-17-2010, 03:15 PM
  2. Servlet mapping
    By cozsmin in forum Java Servlet
    Replies: 1
    Last Post: 04-04-2009, 10:15 AM
  3. Replies: 1
    Last Post: 12-02-2008, 01:23 AM
  4. Replies: 1
    Last Post: 08-07-2007, 04:47 PM
  5. About servlet-mapping
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-14-2007, 07:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •