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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark " Watch " New topic
Author

'The requested resource is not available' error

vysh srini
Greenhorn

Joined: Apr 25, 2009
Posts: 25
Hi all,

I have gone through many topics about this error, but i am not able to arrive at a solution to my problem.

I have a JSP named 'Login.jsp' placed inside a folder called 'LoginPages'. On clicking submit button, it goes to a servlet page named 'LoginController.java' and checks for correct login. If username and pwd matches it goes to the home page, else returns back to the login page itself.

When the username and pwd does not match, it correctly returns back to the login page itself. My problem is, when the username and pwd matches, it gives out this error:

The requested resource (/LoginController) is not available.

But at the first attempt when my username and pwd matches, it works correctly. Only after a wrong entry(uname and pwd not match) it gives out this error. Can anyone tell me why?

My code is as below:


Login.jsp



LoginController.java

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 512

can you show us your web.xml?


Regards, Prasad
SCJP 5 (93%)
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

vysh srini wrote:

It is using relative path.

Relative paths change depending upon what page the links are located on.
Try to use absolute path 'like' below



A.A.Anbarasu
vysh srini
Greenhorn

Joined: Apr 25, 2009
Posts: 25
I used



But no use, I am getting the same error. I also tried using 'application.getRealPath(servlets\LoginController.java)'. It returns the absolute path. But i need to give only the 'url-pattern' (which is in web.xml) in the 'action' tag(if i am not wrong). So it is also not working. Please help me...

My web.xml is as follows:

subhash kumar
Ranch Hand

Joined: Jul 14, 2010
Posts: 63

you browser might clearly telling you which resource is not available with him
you have not posted that name like
The requested resource(LoginPages/UserHomePage.jsp) is not available
so
1. provide the requested resource
or
2. request the available resource


Subhash Kumar
Attitude is everything
vysh srini
Greenhorn

Joined: Apr 25, 2009
Posts: 25
I have already mentioned the error. the error which I am getting is:

The requested resource (/LoginController) is not available.


The resource is present in my project. no doubt about it.....
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Wich folder is the "/LoginController" ? Could you give us the full path?


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
vysh srini
Greenhorn

Joined: Apr 25, 2009
Posts: 25
The "/LoginController" is present in the following location in my project

D:\Netbean Projects\Example\src\java\servlets\LoginController.java
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

What is the return of "request.getContextPath()" ?
vysh srini
Greenhorn

Joined: Apr 25, 2009
Posts: 25
The return of

request.getContextPath();


is

/Example
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61071
    
  66

vysh srini wrote:The "/LoginController" is present in the following location in my project

D:\Netbean Projects\Example\src\java\servlets\LoginController.java


The location of the java file is completely irrelevant.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

I believe thats the problem.

The method is returning /Example when you concat with your Action you will get: "/Example/LoginController" and thats not where your Controller it is.
D:\Netbean Projects\Example\src\java\servlets\LoginController.java

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61071
    
  66

Hebert Coelho wrote: you will get: "/Example/LoginController" and thats not where your Controller it is.

According to the URL mapping that is exactly where the controller "is".

Where the physical class file is located is moot as far as the URL is concerned. All that matters is the mapping.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61071
    
  66

P.S. Are you really using back-slashes in the URL?
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Bear Bibeault wrote:P.S. Are you really using back-slashes in the URL?


I belive hes error is here:



Even here the mapping is not correct.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61071
    
  66

Hebert Coelho wrote:I belive hes error is here:

Random guessing isn't going to do any good. There's nothing wrong with that declaration.

Even here the mapping is not correct.

It's not a mapping; it's the class name.
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Bear Bibeault wrote:
Hebert Coelho wrote:I belive hes error is here:

Random guessing isn't going to do any good. There's nothing wrong with that declaration.

Even here the mapping is not correct.

It's not a mapping; it's the class name.

Up there he said he class was at:
D:\Netbean Projects\Example\src\java\servlets\LoginController.java
And he mapped at
Thats why i said that, I think hes package should be:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61071
    
  66

That does not match the package statement in his source file. But until he let's us know where he put the class file...
vysh srini
Greenhorn

Joined: Apr 25, 2009
Posts: 25
Hebert Coelho wrote:I believe thats the problem.

The method is returning /Example when you concat with your Action you will get: "/Example/LoginController" and thats not where your Controller it is.
D:\Netbean Projects\Example\src\java\servlets\LoginController.java



I have already told that I have used getContextPath() like this:

<form id="form1" name="form1" method="post" action="<%=request.getContextPath()%>\servlets\LoginController.java">



Thats why i said that, I think hes package should be:



I use Netbeans IDE. When I open my project through window explorer, the structure of my project will consists of folders like
build, dist, src, web etc.... Inside my 'web' folder, I will be having my jsp pages. Inside my 'src' folder, i will having all my java codings inside the folder 'src\java'. Since i wanted to give the full path, i gave the full path by right cliking my file and looking into its properties .So the 'java' is not the package name, it is the folder name. So my servlet class



is correct(as it should not include the folder 'java')
Roshan Ramesh
Greenhorn

Joined: Jul 12, 2010
Posts: 8
I believe that a proper mapping of Java resource in the web.xml should resolve your issue.

Few days before there was another discussion thread on somewhat a similar issue. Just have a look at this:

http://www.coderanch.com/t/505924/Servlets/java/Status
vysh srini
Greenhorn

Joined: Apr 25, 2009
Posts: 25
This problem still seems to be there . Can anyone help me
vysh srini
Greenhorn

Joined: Apr 25, 2009
Posts: 25
Atlast the error is resolved!!! The error was with the usage of RequestDispatcher.forward() method. When we use this method, the contents of the page only gets changed but the url still shows the forwarding page, i.e., if i am in page1.jsp and forwarding to page2.jsp, the contents will show page2.jsp but the url will still show page1.jsp only.

So in my case, the url was still showing the 'LoginController' page, from there when i again try to go to 'LoginController' itself, it shows me an error.

I used response.sendRedirect() instead.
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

vysh srini wrote:The error was with the usage of RequestDispatcher.forward() method. When we use this method, the contents of the page only gets changed but the url still shows the forwarding page, i.e., if i am in page1.jsp and forwarding to page2.jsp, the contents will show page2.jsp but the url will still show page1.jsp only.
That's where absolute path comes in picture. If we use absolute path, url will work regardless of current path. This is what I have suggested in my previous post.
Anyhow you got it working
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'The requested resource is not available' error