| Author |
HTTP Status 404
|
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
|
Hi, If I place my html file under WebContent, I am able to load my servlet. If I move html file to some folder under WebContent directory, I am getting HTTP Status 404 error. Please let me know
|
OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
|
 |
Hebert Coelho
Ranch Hand
Joined: Jul 14, 2010
Posts: 754
|
|
If you file is under WebContent you can access by "/file.jsp"
If you move your file, you will have to put the path "folder/file.jsp" or "/folder/file.jsp" i can not tell you for sure now.
Could you post your code here? and your tree folders?
|
[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
|
 |
Victor Hugo M Machado
Greenhorn
Joined: Jan 11, 2011
Posts: 22
|
|
you change your web.xml?
|
 |
Javin Paul
Ranch Hand
Joined: Oct 15, 2010
Posts: 276
|
|
As suggested by Victor , issue could be with url pattern mapping , if you could post your web.xml , we can help probably help better.
|
http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
Here is the completed code:
Web.xmlTestServlet.javaTestMe.htmlWhen I run, http://localhost:8080/ctWeb/html/TestMe.html
ctWeb is my project
html is a directory under Webcontent
When I click button on HTML page, Page is navigated to http://localhost:8080/ctWeb/html/TestServlet.do The following is the error in browser
HTTP Status 404 - /ctWeb/html/TestServlet.do
--------------------------------------------------------------------------------
type Status report
message /ctWeb/html/TestServlet.do
description The requested resource (/ctWeb/html/TestServlet.do) is not available.
|
 |
Victor Hugo M Machado
Greenhorn
Joined: Jan 11, 2011
Posts: 22
|
|
if you try this waht happen?
http://localhost:8080/ctWeb/TestServlet.do
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
This will work because we are calling Servlet directly. Requirement is, I have to call the Servlet from html file that is located in a directory.
|
 |
Victor Hugo M Machado
Greenhorn
Joined: Jan 11, 2011
Posts: 22
|
|
if you change this..
and try this..
http://localhost:8080/ctWeb/html/TestMe.html
what happen?
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
I am getting same Exception,
HTTP Status 404 - /ctWeb/html/TestServlet.do
--------------------------------------------------------------------------------
type Status report
message /ctWeb/html/TestServlet.do
description The requested resource (/ctWeb/html/TestServlet.do) is not available.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56201
|
|
This is covered in the FAQs. You should be using a server-relative URL for the action that starts with the context path.
For example:
P.S. What's with the ".do"? Just because Struts uses that as a pattern to invoke its dispatcher doesn't mean it's necessary for all servlets.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
|
Hi Bear, Please send me the FAQ URL. I couldn't find. BTW, Where should I change it
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56201
|
|
I believe it's one of the JSP FAQs.
This is how to declare a form action to a Servlet. (The same applies to referencing images, scripts and stylesheets).
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
When I use this, I am getting following error
HTTP Status 404 - /ctWeb/html/$%7BpageContext.request.contextPath%7D/TestServlet
--------------------------------------------------------------------------------
type Status report
message /ctWeb/html/$%7BpageContext.request.contextPath%7D/TestServlet
description The requested resource (/ctWeb/html/$%7BpageContext.request.contextPath%7D/TestServlet) is not available.
Bear Bibeault wrote:This is covered in the FAQs. You should be using a server-relative URL for the action that starts with the context path.
For example:
P.S. What's with the ".do"? Just because Struts uses that as a pattern to invoke its dispatcher doesn't mean it's necessary for all servlets.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56201
|
|
Looks like your web is is misconfigured such that the EL is not enabled.
Be sure that your web.xml is correctly declared as outlined in the JSP FAQ. (For example, if you are using the Servlets 2.3 DTD in your web.xml, it's wrong.)
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
I don't have DTD. I see xsd in my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
</web-app>
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56201
|
|
Then the EL should be enabled in your JSPs.
What happens when you hit a JSP that contains just the following:?
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
|
7 is displayed in the browser.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56201
|
|
OK, the EL is correctly enabled. Be sure you are not disabling it on the page in question.
Then take a look at the HTML for the <form> element after is has been sent to the browser. Does it look correct?
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
|
I did not understand "Be sure you are not disabling it on the page in question. ". Also, I did not understand "Then take a look at the HTML for the <form> element after is has been sent to the browser". Please advice..
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56201
|
|
1) There are directives that will disable the EL. Be sure you are not using them.
2) Look at the HTML in the browser. Usually something like "View source" on the menus.
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
Hi Bear,
I do not have any directives as given in the source code above. View source looks good to me.
Bear Bibeault wrote:1) There are directives that will disable the EL. Be sure you are not using them.
2) Look at the HTML in the browser. Usually something like "View source" on the menus.
|
 |
Nick White Ro
Greenhorn
Joined: Jan 27, 2010
Posts: 15
|
|
First of all, rename your "TestMe.html" to "TestMe.jsp".
Then, modify your form declaration to: .
After that, test the JSP in the browser and verify that in the outputed HTML (view source), the action in the form is "/ctWeb/TestServlet.do".
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
I see the following, when I say, view--> source
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<form action="/ctWeb/TestServlet.do">
<input type="submit" value="Send"></form>
</body>
</html>
|
 |
Nick White Ro
Greenhorn
Joined: Jan 27, 2010
Posts: 15
|
|
|
And does the servlet work?
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
Yes.
Nick White Ro wrote:And does the servlet work?
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
|
It is working fine now..Thanks Nick and Bear. Renaming from "TestMe.html" to "TestMe.jsp" fixed the issue.
|
 |
 |
|
|
subject: HTTP Status 404
|
|
|