File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HTTP Status 404 - Servlet 'x' is not available. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP Status 404 - Servlet Watch "HTTP Status 404 - Servlet New topic
Author

HTTP Status 404 - Servlet 'x' is not available.

Jose Alvarez
Greenhorn

Joined: Jan 23, 2012
Posts: 11
Well, I'm doing a web page using Glassfish tools bundle for Eclipse (I use the server provided by the Glassfish).

I have a package called "Interfaz" where I put the servlets. I added a servlet called "RegistroConciertos" but when I try to execute this, I receive the exception mentioned in the title of my topic. I try to add more servlets, but I receive the same exception. With the servlets what I have created above, I don't have problems.

At the first time I try to run the servlet after the server starts, I receive the exception HTTP Status 500 - javax.servlet.ServletException: PWC1397: Wrapper cannot find servlet class 'x' or a class it depends on.
And then, if I touch "Refresh" in the WebBrowser provides by GlassFish, I receive the exception HTTP 404.

What can I do?

Thanks for all.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

Did you add the proper url-mapping elements to your web.xml file?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jose Alvarez
Greenhorn

Joined: Jan 23, 2012
Posts: 11
Rob Spoor wrote:Did you add the proper url-mapping elements to your web.xml file?


Yes, because Glassfish add the elements automatically. But I saw the web.xml file and the tags are correctly.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Don't tell us, show us.

Otherwise, all we can do is to guess.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jose Alvarez
Greenhorn

Joined: Jan 23, 2012
Posts: 11
Bear Bibeault wrote:Don't tell us, show us.

Otherwise, all we can do is to guess.


What do you need to see? Tell me and I show what you want.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

Jose Juan wrote:But I saw the web.xml file and the tags are correctly.


Then show us THAT.
Jose Alvarez
Greenhorn

Joined: Jan 23, 2012
Posts: 11
Well, I used the old version of the web page and it works. Thanks for all.
shivam purohit
Greenhorn

Joined: May 02, 2011
Posts: 12

Hi all,
I am getting an error while running hello world program in eclipse using tomcat as plug in .

"The requested resource (/ServletExam/) is not available".

My web.xml is following:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!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>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>

I think i have either missed something in this or something wrong.
I have read some post regarding this but could not get any help.
please assit me.
Thanks.

please help me asap.as its urgent.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

There is no URL mapping for "/ServletExam/", only for "/HelloWorld". And you shouldn't use classes in the default package.

shivam purohit wrote:please help me asap.as its urgent.

Please EaseUp. There is no such thing as urgent or "ASAP" around here.
shivam purohit
Greenhorn

Joined: May 02, 2011
Posts: 12

Rob Spoor wrote:There is no URL mapping for "/ServletExam/", only for "/HelloWorld". And you shouldn't use classes in the default package.

shivam purohit wrote:please help me asap.as its urgent.

Please EaseUp. There is no such thing as urgent or "ASAP" around here.



Hi,
as i am a new bee here and new to servlet too.
can you please explain through code. so i can undrstand.
thnks
shivam purohit
Greenhorn

Joined: May 02, 2011
Posts: 12

Hi,
as i am a new bee here and new to servlet too.
can you please explain through code. so i can undrstand.

I have changed my project name from ServletExam to HelloWorld.
thnks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

Can you tell us which URL you're trying to open?

You only have one URL mapping, for /HelloWorld. You have no welcome file list. That means that you can only access two types of URLs (if your project is still named ServletExam):
- http://localhost:8080/ServletExam/HelloWorld which will open the servlet.
- http://localhost:8080/ServletExam/xxx where xxx is a direct path to a JSP file, HTML file, image etc. In other words, anything that isn't a servlet (or inside the WEB-INF folder).
shivam purohit
Greenhorn

Joined: May 02, 2011
Posts: 12

1.At first ,i am using tomcat as plug in in eclipse (so not using http://localhost:8080)
2. Yes i ddnt use any jsp any html page, cos i hv heard/read somewhere that we can use servlet without jsp also.
then cn i use for the same.
or guide me if its not possible.(
in this case i will add a new jsp/html )page then will try to run.


details:
projet name:Hello1
java file in src folder : HelloWorld

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head><title>Hello World</title></title>");
pw.println("<body>");
pw.println("<h1>Hello World</h1>");
pw.println("</body></html>");
}
}


web.xml in web-inf

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!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 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/HelloWorld*</url-pattern>
</servlet-mapping>
</web-app>


jar file in web-inf\lib---servlet-api.jar



thts what i am using.
shivam purohit
Greenhorn

Joined: May 02, 2011
Posts: 12

In elipse's browser url is :::: http://localhost:8180/Hello1/
as i have changed port cos 8080 is used by oracle.

Thnks:-)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

shivam purohit wrote:ddnt ... cos ... hv ... cn ... thts ...Thnks

Please UseRealWords.

With that web.xml file only URLs that start with http://localhost:8180/Hello1/HelloWorld are supported.
shivam purohit
Greenhorn

Joined: May 02, 2011
Posts: 12

Hi Rob,
Thanks
But Its still not working and giving following error:

The requested resource (/Hello1/HelloWorld) is not available.


Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 539

Try putting the servlet in a package.
shivam purohit
Greenhorn

Joined: May 02, 2011
Posts: 12

hi prasad,
are you getting something wrong in my code.

OK if i will put that servlet into package, in web.xml,what changes should i have to do??
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 539

In web.xml, you need to change the value of <servlet-class> to hold the fully qualified name of the servlet.
bindu sadanandan
Greenhorn

Joined: Jul 31, 2012
Posts: 6
Kindly ensure that in each servlet code before each of the imports...the following code is entered

package Interfaz;

else it wont be able to find that servlet under the package even though you might see the servlet in the tree structure under Interfaz.
 
wood burning stoves
 
subject: HTTP Status 404 - Servlet 'x' is not available.