Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes Cannot find file..? Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cannot find file..? Help" Watch "Cannot find file..? Help" New topic
Author

Cannot find file..? Help

Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Guys,

Im new to Servlets JSP's etc.., having some issues with the stuff below.

I have a servlet (just a test one for now) that in its post method just forwards the requester to google ,

response.sendRedirect("http://www.google.com");
return;

The JSP that calls this is has the following

<form method="POST" action="../servlet/servlets.UploadServlet"/>

The web.xml has the following code (I modified after reading some of the postings)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE web-app (View Source for full doctype...)>
- <web-app>
<display-name>mcaiyzm2 Web Application</display-name>
<description>mcaiyzm2 web application for JRun</description>
- <servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>UploadServlet</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/servlets</url-pattern>
</servlet-mapping>
</web-app>

The servlet is stored in the directory structure /web-inf/classes/servlets

When i click the button, in the url, it says "The file that you requested could not be found on this server. "

What have I done wrong?

All the help that u can give me will be appreciated.

Thanks in advance
Zein
danny liu
Ranch Hand

Joined: Jan 22, 2004
Posts: 185
Bug 1, servlet deployment setup, it should be

<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>servlets.UploadServlet</servlet-class>
</servlet>

Bug 2, url mapping

<form method="POST" action="../servlet/servlets.UploadServlet"/>

does not match

<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/servlets</url-pattern>
</servlet-mapping>
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Danny,

Thanks for the above, still doesnt work. Says HTTP 404 - File not found.

<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>servlets.UploadServlet</servlet-class>
</servlet>

Web.xml has been modified as above. Also post action has been modified to look like

<form method="POST" action="servlets.UploadServlet"/>

with the corresponding web.xml like below

<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/servlets</url-pattern>
</servlet-mapping>

Any ideas?

Regards
Zein
Heonkoo Lee
Ranch Hand

Joined: Feb 10, 2005
Posts: 85
You mapped the servlet to the url, /servlets, and tried to invoke 'servlets.UploadServlet' by the form action. That's why you got the status code 404.

Try again with <form method="POST" action="/servlets"/>.

Regards,
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Well guys,

This issue is still out standing, now the error is

HTTP 405 - Resource not allowed
Internet Information Services

The jsp post reads
<form method="POST" action="/servlets"/>

The web.xml is as follows

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE web-app (View Source for full doctype...)>
- <web-app>
<display-name>mcaiyzm2 Web Application</display-name>
<description>mcaiyzm2 web application for JRun</description>
- <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
- <servlet>
- <init-param>
<param-name>browseDirs</param-name>
<param-value>false</param-value>
</init-param>
<servlet-name>FileServlet</servlet-name>
<servlet-class>jrun.servlet.file.FileServlet</servlet-class>
<description>This servlet may override a corresponding FileServlet in SERVER-INF/default-web.xml.If removed, the servlet in default-web.xml will be used.</description>
</servlet>
<distributable>false</distributable>
- <servlet>
<!-- Above this is default -->
<servlet-name>UploadServlet</servlet-name>
<servlet-class>servlets.UploadServlet</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/servlets</url-pattern>
</servlet-mapping>
</web-app>

Directory structure is

WEB-INF\classes\servlets


And the post method is as follow

public void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<HTML>");
out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello World</BIG>");
out.println("</BODY></HTML>");

}
What have i dont wrong now? Its all correct as far as i can see?!!!
Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
in the web.xwl in the servlet-mapping tag should be

<url-pattern>/servlet/servlets/UploadServlet</url-pattern>


We must know, we will know. -- David Hilbert
Heonkoo Lee
Ranch Hand

Joined: Feb 10, 2005
Posts: 85
The url in <url-pattern>/servlets</url-pattern> seems like causing the problem. '/servlet' and '/servlets' might be used by the servlet container to dynamically invoke servlets with no mapping information when the user sends a request by calling /servlet/packagename.SomeServlet.

So, why don't you try with different url-pattern like

<url-pattern>/UploadFile/*</url-pattern>

and use <form method="POST" action="/UploadFile"> in the jsp.

This issue is still out standing, now the error is

HTTP 405 - Resource not allowed
Internet Information Services

Looks like it's from IIS web server. What servlet container are you using?
[ April 03, 2005: Message edited by: Heonkoo Lee ]
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Cheers Guys , the problem has been kinda solved.

See im on a university network etc.., soo theres alot of thing we dont have control over, for starters installing the server etc.

It turns out some 'environmental' varible [quote from the technician] isnt right, the lab technician will fix it later.

Damn thing had me pulling my hair out..
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Well ok the problem is completely solved now.

instead of using ../servlet, I had to use ./servlet [not one dot]. Reason is, my jsp's etc.. are not in a folder, they just lie in the root directory.

Thanks for the help guys, really appreciated
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Cannot find file..? Help