This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Error: Requested resourse() not available Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error: Requested resourse() not available" Watch "Error: Requested resourse() not available" New topic
Author

Error: Requested resourse() not available

Pavani Kokkiragadda
Greenhorn

Joined: Jan 19, 2011
Posts: 20
Hi frnds!!

I am doing a simple web form submission which sends email to mail id.
I am getting error in my first page itself!!

Once i submit my form its not getting directed to myservlet.

here is my html/jsp page!!

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Home</title>
</head>
<body>
<form method="POST" action="/MyServlet">
<p> Name : <input name="Name" type="text" size="8"> </p>
<p> EmailID :<input name="Email" type="text" size="25" ></p>
<p> <input name="submit" type="submit" value="submit" > <input name="cancel" type="reset"> </p>
</form>
</body>
</html>

I tried giving action with different values like...

/src/java/mypackage/myservlet.java
mypackage/Myservlet.java and so on...

But nothing worked out.
I am getting error message from my glassfish server

b]requested resource() not found.[/b]please help me find solution!!

thanks
Pavani
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

How is the servlet mapped in the deployment descriptor? Is your app the ROOT context? If not, you need to add the context path to the action URL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
/src/java/mypackage/myservlet.java
mypackage/Myservlet.java and so on...


Servlet container will not compile those classes for you - it is the location of the compiled .class files that is important.

Bill
Pavani Kokkiragadda
Greenhorn

Joined: Jan 19, 2011
Posts: 20
William Brogden wrote:
/src/java/mypackage/myservlet.java
mypackage/Myservlet.java and so on...


Servlet container will not compile those classes for you - it is the location of the compiled .class files that is important.

Bill


Yeah..I know..
I am using Netbeans 6.9 for doing this. Here in my web application, I am unable to compile(or create class file) the Servlets. I tried doing through command promt..but i m getting errors!!

Please advice!!
prem pillai
Ranch Hand

Joined: Nov 02, 2007
Posts: 87

nsk pavaniI am unable to compile(or create class file) the Servlets. I tried doing through command promt..but i m getting errors!! Please advice!![/quote wrote:

You need to provide more details for futher advice/help ... Your servlet class details like Name , Package (if possible full code itself) , servlet declaration and servlet mapping from your web.xml , if you are getting compilation errors-those errors etc ...
Pavani Kokkiragadda
Greenhorn

Joined: Jan 19, 2011
Posts: 20
prem pillai wrote:
nsk pavaniI am unable to compile(or create class file) the Servlets. I tried doing through command promt..but i m getting errors!! Please advice!![/quote wrote:

You need to provide more details for futher advice/help ... Your servlet class details like Name , Package (if possible full code itself) , servlet declaration and servlet mapping from your web.xml , if you are getting compilation errors-those errors etc ...


Hi,
My index.jsp page as shown in my first page...

n my Servlet class is in mypackage

package mypackage;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String EmailID= request.getParameter("EMail");
SendMail sm= new SendMail();
sm.sendMail(EmailID);
}

}

I have Send Mail class which send email and working perfectly fine with opther applications...

Now here in NetBeans IDE i am not getting amy compilation errors!
In web.xml,the fields are:

ServletName: MyServlet
Servlet class: mypackage.MyServlet
URL: /MyServlet

Now I know that in action field of form tag, I should give "/MyServlet".
I could run index.jsp page and after submitting my values, it should go to MyServlet but,
I am getting error in my glassfish server : "requested resource() not available". and the url on IE shows : " http://localhost:8080/MyServlet"


And one more thing is, I cannot see .class files of MyServlet n SendMail classes. how do I compile these 2 classes??
So, this is my problem..Please advice me!!
Pavani Kokkiragadda
Greenhorn

Joined: Jan 19, 2011
Posts: 20
Bear Bibeault wrote:How is the servlet mapped in the deployment descriptor? Is your app the ROOT context? If not, you need to add the context path to the action URL.


Yes my is the Root Context
And My Servlet is mapped like following:
Servlet Name: MyServlet
Servlet class: mypackage.MyServlet
url: /MyServlet

can you please tell me where I went wrong?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Telling us the servlet mapping is not useful. Show us the servlet mapping.
Pavani Kokkiragadda
Greenhorn

Joined: Jan 19, 2011
Posts: 20
Bear Bibeault wrote:Telling us the servlet mapping is not useful. Show us the servlet mapping.


<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>mypackage.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</servlet>

does this help??..I m struggling with this since 2 days..
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Your servlet mapping looks fine... But there is an servlet end tag at the end?
I am unable to compile(or create class file) the Servlets. I tried doing through command promt..but i m getting errors!!

So you don't have servlet classes (.class files) inside the web app (i.e.: <context>/WEB-INF/classes/ dir)? Then first you need to compile them and put in the correct location as I mentioned. What's the issue you have in compiling?

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Pavani Kokkiragadda
Greenhorn

Joined: Jan 19, 2011
Posts: 20
Vijitha Kumara wrote:Your servlet mapping looks fine... But there is an servlet end tag at the end?
I am unable to compile(or create class file) the Servlets. I tried doing through command promt..but i m getting errors!!

So you don't have servlet classes (.class files) inside the web app (i.e.: <context>/WEB-INF/classes/ dir)? Then first you need to compile them and put in the correct location as I mentioned. What's the issue you have in compiling?


Hi Vijitha,

Now, I could see my classes in the correct location!! (i.e., /WEBINF/classes/package/). But the error is still the same. I m not able to find where it went wrong!! so seeking some experts advice...Please help me!!

I can provide any further info..ask me if you need any!!

Thanks
nskp
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Ok then.
Use "./MyServlet" in the action like below

in your JSP.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Vijitha Kumara wrote:Ok then.
Use "./MyServlet" in the action like below

No. Do not.

Using page-relative URLs is a poor practice and will lead to nothing but problems now or in the future. Follow best practices and use server-relative URLs that begin with the context path of the application. Be sure to use ${pageContext.request.contextPath} to look up the context path programatically.

Pavani Kokkiragadda
Greenhorn

Joined: Jan 19, 2011
Posts: 20
Bear Bibeault wrote:
Vijitha Kumara wrote:Ok then.
Use "./MyServlet" in the action like below

No. Do not.

Using page-relative URLs is a poor practice and will lead to nothing but problems now or in the future. Follow best practices and use server-relative URLs that begin with the context path of the application. Be sure to use ${pageContext.request.contextPath} to look up the context path programatically.



Hi,

I did the way Vijitha adviced!! and it is working now..
But I do want to follow best practices..I am novice to this subject..
Please tell me how do I do the above said context path? Can you please explain?

Anyway Thanks Vijitha and Bear Bibeault

look forward for your reply
-nskp
Pavani Kokkiragadda
Greenhorn

Joined: Jan 19, 2011
Posts: 20
nsk pavani wrote:
Bear Bibeault wrote:
Vijitha Kumara wrote:Ok then.
Use "./MyServlet" in the action like below

No. Do not.

Using page-relative URLs is a poor practice and will lead to nothing but problems now or in the future. Follow best practices and use server-relative URLs that begin with the context path of the application. Be sure to use ${pageContext.request.contextPath} to look up the context path programatically.



I got it!!
Thanks for Advices guys!! They are really helpful!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error: Requested resourse() not available
 
Similar Threads
HTTP Status 404 Error - error while calling a servlet from a jsp
Can't access HTML form page in browser
Problem calling a servlet from JSP
Not able to set attribute in JSP
calling jsp directl from HTML form