Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error: Requested resourse() not available

 
Pavani Kokkiragadda
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Telling us the servlet mapping is not useful. Show us the servlet mapping.
 
Pavani Kokkiragadda
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Pavani Kokkiragadda
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok then.
Use "./MyServlet" in the action like below

in your JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic