Results 1 to 8 of 8
- 06-11-2012, 12:20 AM #1
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
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:
I'm deffinately doing something wrong with this. Thanks for the help!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>Last edited by proksy; 06-11-2012 at 01:35 AM.
- 06-11-2012, 11:06 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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.
- 06-21-2012, 05:32 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
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 TollsLast edited by proksy; 06-21-2012 at 05:39 PM.
- 06-21-2012, 05:53 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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.
- 06-21-2012, 05:55 PM #5
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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.Website: Learn Java by Examples
- 06-21-2012, 08:20 PM #6
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
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
This is what I have in my action for my form or buttonJava 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>
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!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>
- 06-21-2012, 11:34 PM #7
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
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.
- 10-19-2012, 05:22 PM #8
Member
- Join Date
- Sep 2012
- Location
- Guntur, India
- Posts
- 27
- Rep Power
- 0
Similar Threads
-
Servlet Mapping question.
By Mega Man X in forum Java ServletReplies: 2Last Post: 02-17-2010, 02:15 PM -
Servlet mapping
By cozsmin in forum Java ServletReplies: 1Last Post: 04-04-2009, 09:15 AM -
Servlet - apache tomcat/glassfish server shuts down on servlet usage
By StewS in forum Java ServletReplies: 1Last Post: 12-02-2008, 12:23 AM -
javax.servlet.ServletException: Wrapper cannot find servlet class util.t2
By osval in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 03:47 PM -
About servlet-mapping
By Heather in forum Java ServletReplies: 1Last Post: 07-14-2007, 06:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks