• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The requested resource is not available

 
gary nubold
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arg!!! Ben wins by a nose!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic