• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet not running "The requested resource is not available"

 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My servlets are not running.

Login.java


WelcomeServlet.java


Index.html


web.xml


It's not running. I'm not sure why
Capture.JPG
[Thumbnail for Capture.JPG]
Package structure
 
Stefan Evans
Bartender
Posts: 1807
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you me more specific about what is not working?
What url are you hitting that gives this response?


How are you wanting to specify your URLs? Right now you are using both @WebServlet annotations and entries in web.xml

From a quick glance at your web.xml file, the first thing I would suggest is to provide full package names for your servlet-class elements.
i.e.<servlet-class>Login</servlet-class> should be: <servlet-class>requestdispatcher.Login</servlet-class>


Check out the log for your container to see if there are any startup messages.
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ALso, you have:

but your servlet is defined as:

so your form action is not going to get there.

Actually, you have both a web.xml and you are using annotations.
I have no idea which one would take precedence...even then, the "/Login" used in the annotation case a capital 'L'. I'm fairly sure this is case sensitive.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what is being done here. I am trying to learn servlet but couldn't get past first example lol .. I'll try the changes suggested. I have no idea what web.xml is doing
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've deleted the web.xml file. Here's the new code. Also how to start this servlet ? from index.html ?

Login.java


WelcomeServlet.java


index.html


What other changes needs to be made ? Or is there a good tutorial for servlets in eclipse.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you prefixing the paths with "/requestdispatcher."? That's really bizarre.

I'd also make the paths all lowercase.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


All classes used in servlets MUST be in packages and the class file stored in a directory that corresponds.

The reason being that the JVM will look for classes without a declared package in the "current" directory - which you have no control over. When the class is not found, that is the error you get.

I think the FAQ for servlets discusses this.

Bill
 
Stefan Evans
Bartender
Posts: 1807
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, you're using Servlet 3.0 annotations.
I believe that means you can do away with the web.xml file altogether (though at some point it would be good to understand what it is, and what it does)
Yes if you specify servlet entries in web.xml then need to be fully qualified. But in this case, getting rid of the web.xml file is the right thing to do.

As other people have pointed out, your MAIN problem is your URLs between your resources.
I asked you before what url you were going to to get this response. That question still remains unanswered - and it is fundamental to the problem.
You should be able to see in browser what URL you actually invoked.

From your earlier descriptions, I think these URLs should be:
/Servlets/index.html - your index file
/Servlets/Login - your login action
/Servlets/WelcomeServlet - your welcome page once logged in.

If you get anything different, then we need to fix that.
The "Servlets" part I am taking from your Project name and web.xml file - it is the "context path" of your application.

Note! These are the URLS I think you should see in your browser. They are NOT the explicit URLs you should use in your code. The context path "Servlets" should never enter into any URL in your application. :-)
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me that if the JVM can't find the servlet class file, annotations are not going to do any good.

Bill

 
Stefan Evans
Bartender
Posts: 1807
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. But it will find the annotated class.
I'm not entirely certain what it is that is processing the classes and looking for the annotations, but I know it ain't web.xml.
The annotation on the class file REPLACES what you would normally put in web.xml.
Putting the annotation there means that the class will register itself as a servlet, and create an appropriate servlet mapping to itself.

The servlet configuration in web.xml is incorrect, but is a red herring as far as why the "requested resource is not available"
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you sure it will find the compiled annotated class file? If the OP said where that file was placed I missed it.

Bill
 
Stefan Evans
Bartender
Posts: 1807
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>Why are you sure it will find the compiled annotated class file?

The evidence for that was
- screenshot of Eclipse package structure in the OP
- I copied/pasted the code into Eclipse to duplicate the issue.





 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:

As other people have pointed out, your MAIN problem is your URLs between your resources.
I asked you before what url you were going to to get this response. That question still remains unanswered - and it is fundamental to the problem.
You should be able to see in browser what URL you actually invoked.

From your earlier descriptions, I think these URLs should be:
/Servlets/index.html - your index file
/Servlets/Login - your login action
/Servlets/WelcomeServlet - your welcome page once logged in.

If you get anything different, then we need to fix that.



I was running the servlet from indexfile(html). But after pressing submit. It's searching the Login under webcontent folder.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help. I think we should proceed step by step so figure out where I'm going wrong.
I tried recreating the problem so that you guys could have a better view. Here it is -

HTMLFromIndexFile.java - This is running and showing HTML message when I run on server.


index.html - This is running from notepad++ .


I want to display servlet page when i click on button. However it's redirecting to a different folder. I believe i need to change something in action attribute. There is no web.xml file.

Here is the link after pressing button - file:///D:/Eclipse_Workspace/workspace/JavaServlets/WebContent/WEB-INF/HTMLFromIndexFile?
This is wrong. My servlet is not there. This is the problem i'm facing.

Capture.JPG
[Thumbnail for Capture.JPG]
Directory Structure
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you opening that index.html?

Is it deployed to your server?
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:How are you opening that index.html?

Is it deployed to your server?


I'm running that from np++.
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which implies to me it's not from a server, so the browser treats it as a local file and looks in the same directory or thereabouts.

You can't just open up an html file and expect it to work as if it were on a server, I'm afraid.
You need to deploy it as part of your application.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't hit me !!

Sorry for all that confusion. I got it now. I was not running the index.html on a server and it was not outside web-inf sometimes.

The pre-requisites were -
1: index.html should be under webContent but not under web-inf.
2: the html page should run on server.

If it weren't running on server then by default the index.html was looking for action url under same folder i.e web content.
I wasted so much time on the silly mistake
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a learning exercise.
At least this way you'll probably remember it!
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol .. yeah .. I'll remember it now :p

Thanks to all people once again. It's a great community
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic