wood burning stoves 2.0*
The moose likes Servlets and the fly likes The requested resource is not available Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "The requested resource is not available" Watch "The requested resource is not available" New topic
Author

The requested resource is not available

gary nubold
Greenhorn

Joined: Apr 18, 2005
Posts: 1
Hi
i have been having problems with getting a servlet to run from a form. I have configured the web.xml as follows


when I run http://host/company/ChangePassword it works but when I try to access it from a jsp as part of a form i.e <form action="/ChangePassword" method="POST"> I get the 404 error.

I am running the web app on tomcat 5.0.28

thanks for any help
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410



A very common mistake.
You're not including the contextPath (or company name as you called it) in your action attribute.

Quick fix:
Remove the forward slash.


Best practice:
Read the contextPath dynamically from the request object:

JSP 2.0 example:
<form action="${pageContext.request.contextPath}/ChangePassword" method="POST">

Older versions:
<form action="<%=request.getContextPath()%>/ChangePassword" method="POST">


If you do this with all of your links, form actions, and src attributes, everything in your app will be relative to the root of the web application and will be futur proofed against contextPath changes.
[ July 19, 2007: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Originally posted by gary nubold:
when I run http://host/company/ChangePassword it works but when I try to access it from a jsp as part of a form i.e <form action="/ChangePassword" method="POST"> I get the 404 error.

Compare the URLs. What's missing from your form action URL?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Arg!!! Ben wins by a nose!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The requested resource is not available
 
Similar Threads
javax.naming.NamingException: Could not dereference object
Struts portlet on liferay giving Null pointer exception
Blank page returned when filters are used with struts
Simple Servlet Not Working
url pattern