• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The requested resource (/servlet/LoginServlet) is not available

 
Orem Hun
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need help with the above error.
I've a mbWelcome.jsp which has the following POST action:
<form name="mbWelcome" method="POST" action="/servlet/LoginServlet">

And the web.xml lines for this servlet are:

<servlet>
<servlet-name>LoginServlet</servlet-name>
<display-name>LoginServlet</display-name>
<servlet-class>minibank.web.LoginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/servlet/LoginServlet</url-pattern>
</servlet-mapping>

I've LoginServlet.class file in Tomcat installation webapps/MiniBank/WEB-INF/classes/minibank/web/LoginServlet.class

When I submit from mbWelcome.jsp, the LoginServlet action not being invoked, Tomcat is not able to see the class LoginServlet, and giving error in the subject. I think some thing is missing in my configuration, can any one explain this behaviour.

thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need the 'servlet' keyword in your url.
Try:
<form name="mbWelcome" method="POST" action="LoginServlet">
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"java_r",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Orem Hun
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried with the following: <form name="mbWelcome" method="POST" action="LoginServlet">

It did not work. The URL it looks for the servlet now is: http://localhost/MiniBank/Jsp/LoginServlet

Basically, this corresponds to same directory where the mbWelcome.jsp exists. I've brought up mbWelcome.jsp using http://localhost/MiniBank/Jsp/mbWelcome.jsp

For some reason, it looks for the Servlet class in the local dir. I thought adding the following lines to web.xml would make it look at: webapps/MiniBank/WEB-INF/classes/minibank/web/LoginServlet.class

web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">


<web-app id="WebApp">
<display-name>MyBankWeb</display-name>

<servlet>
<servlet-name>LoginServlet</servlet-name>
<display-name>LoginServlet</display-name>
<servlet-class>minibank.web.LoginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/servlet/LoginServlet</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>mbWelcome.jsp</welcome-file>
</welcome-file-list>
</web-app>
-------

I think, some how the URL is not able to be mapped to the correct location of the class.

thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It needs to match the url-pattern (but without the beginning slash.
Sorry, I did not notice that you had /servlet in your mapping.

<url-pattern>/servlet/LoginServlet</url-pattern>

Try:
<form name="mbWelcome" method="POST" action="servlet/LoginServlet">

The slash at the beginning will cause your browser to omit the contextPath.
This is probably what the issue was.
 
Orem Hun
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not realize the issue with the starting slash, I've corrected that. However, that did not change any of the behaviour ( I did restart Tomcat).

Now jsp has: <form name="mbWelcome" method="POST" action="servlet/LoginServlet">

web.xml has:
<servlet>
<servlet-name>LoginServlet</servlet-name>
<display-name>LoginServlet</display-name>
<servlet-class>minibank.web.LoginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/servlet/LoginServlet</url-pattern>
</servlet-mapping>

This is first time writing JSP/servlet app for Tomcat, I don't have a working example to compare, so it is mysterious for me to how to make Tomcat run my servlet class.

Appreciate all your time.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want some examples, look at http://simple.souther.us.
It's a collection of demo apps, packaged as war files that can be deployed in a running instance of Tomcat with a couple mouseclicks.
 
Orem Hun
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, thanks, I am looking at some of them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic