Skip to main content

Glassfish requested resource () is not available servlet issue

3 replies [Last post]
pimathieu
Offline
Joined: 2010-01-12

I'm a beginner trying to get a very simple servlet working.

The servlet is HelloWorldServlet (code below).
I have placed the class in the HelloWorldServlet/WEB_INF/classes folder.
I configure the web.xml as indicated below.

I can deploy the application successfully with the command:
asadmin deploy HelloWorldServlet

I can then see the application under Applications in the Glassfish web admin interface. I then click on Launch to start the app and I get the following:

HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.

Any ideas on how to fix this are appreciated. Thanks.

HelloWorldServlet compiled in HelloWorldServlet/WEB_INF/classes:
--------------------------------------------------------------------------------------------------
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorldServlet extends HttpServlet
{
public void doGet(HttpServletRequest inRequest, HttpServletResponse outResponse)
throws ServletException, IOException
{
PrintWriter out = null;

outResponse.setContentType("test/html");
out = outResponse.getWriter();

out.println("Hello World");
}

public void doPost(HttpServletRequest inRequest, HttpServletResponse outResponse)
throws ServletException, IOException
{
doGet(inRequest, outResponse);
}
}
--------------------------------------------------------------------------------

web.xml in HelloWorldServlet/WEB_INF:
---------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>

HelloWorldServlet
Hello world test servlet

HelloWorldServlet
HelloWorldServlet

HelloWorldServlet
/hey

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pimathieu
Offline
Joined: 2010-01-12

This has helped a lot. I put an index.html in my root and the error has gone away.

Thank you Jan.

Jan Luehe

On 01/13/10 05:22 AM, glassfish@javadesktop.org wrote:
> This has helped a lot. I put an index.html in my root and the error has gone away.
>
> Thank you Jan.
>

Great!

Note that you could also configure your app so that your
HelloWorldServlet is served as the welcome page. The Servlet 3.0 spec
makes this possible by requiring that the web container also consider
welcome files mapped to Servlets instead of just static resources, see
SRV 10.10 ("Welcome Files"):

The Web server must append each welcome file in the order specified in
the deployment descriptor to the partial request and check whether a
static resource in the WAR is mapped to that request URI. *If no match
is found, the Web server MUST again append each welcome file in the
order specified in the deployment descriptor to the partial request
and check if a servlet is mapped to that request URI.*

You could achieve this by adding "/index.html" to the list of URL
patterns mapped to your Servlet:


HelloWorldServlet
/hey
/index.html

After making the above change and redeploying your app, clicking on
your app's launch link will cause the string "Hello World" to be
returned as the response.

Hope this helps.

Jan

> [Message sent by forum member 'pimathieu' (mathieu@nrcan.gc.ca)]
>
> http://forums.java.net/jive/thread.jspa?messageID=380626
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Jan Luehe

When you launch an application from the admin console, you will access
it at its document root. In your example, the launch link would look
as follows:

localhost:8080/HelloWorldServlet/

When you access an application at its document root, the container
will check the application's document root folder for any welcome pages.

You can define your own welcome page(s) in your application, but
unless you do so, your application will inherit a predefined list of welcome
pages from your domain's default-web.xml descriptor, which looks like this:


index.html
index.htm
index.jsp

Try placing a file with one of the above names in your application's
document
root, and you'll notice that when you click on the launch link for your
app, the
contents of its welcome page will be served.

If your app does not contain any welcome pages, the container would
normally generate a directory listing of its docroot folder. By
default, this functionality is disabled for security reasons, but can
be enabled by setting the init parameter with name "listings" of the
"default" Servlet, which is declared in default-web.xml, to "true".
This will enable directory listings globally (for all apps).
Alternatively, you
may enable directory listings for your app only, by setting "listings" to
"true" in your app's sun-web.xml descriptor.

Hope this helps.

Jan

On 01/12/10 12:29 PM, glassfish@javadesktop.org wrote:
> I'm a beginner trying to get a very simple servlet working.


>
> The servlet is HelloWorldServlet (code below).
> I have placed the class in the HelloWorldServlet/WEB_INF/classes folder.
> I configure the web.xml as indicated below.


>
> I can deploy the application successfully with the command:
> asadmin deploy HelloWorldServlet


>
> I can then see the application under Applications in the Glassfish web admin interface. I then click on Launch to start the app and I get the following:


>
> HTTP Status 404 -

> type Status report

> message

> descriptionThe requested resource () is not available.


>
> Any ideas on how to fix this are appreciated. Thanks.


>


>
> HelloWorldServlet compiled in HelloWorldServlet/WEB_INF/classes:


> --------------------------------------------------------------------------------------------------


> import java.sql.*;

> import java.io.*;

> import java.util.*;

> import javax.servlet.*;

> import javax.servlet.http.*;

>

> public class HelloWorldServlet extends HttpServlet

> {

> public void doGet(HttpServletRequest inRequest, HttpServletResponse outResponse)

> throws ServletException, IOException

> {

> PrintWriter out = null;

>

> outResponse.setContentType("test/html");

> out = outResponse.getWriter();

>

> out.println("Hello World");

> }

>

> public void doPost(HttpServletRequest inRequest, HttpServletResponse outResponse)

> throws ServletException, IOException

> {

> doGet(inRequest, outResponse);

> }

> }

> --------------------------------------------------------------------------------

>

> web.xml in HelloWorldServlet/WEB_INF:

> ---------------------------------------------------------------------------------

>

>

>

>

> HelloWorldServlet

> Hello world test servlet

>

>

> HelloWorldServlet

> HelloWorldServlet

>


>

>

> HelloWorldServlet

> /hey

>


>

>


> [Message sent by forum member 'pimathieu' (mathieu@nrcan.gc.ca)]
>
> http://forums.java.net/jive/thread.jspa?messageID=380428
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net