2

I have a simple servlet say com.test.HelloWorld.class

then I create these folders tree:

WEB-INF -->
            lib
            classes -->
                    com -->
                           test -->
                                HelloWorld.class
web.xml

where web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
           http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         version="3.0">
  <servlet>
    <servlet-name>helloworld</servlet-name>
    <servlet-class>
      com.test.HelloWorld
    </servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>helloworld</servlet-name>
    <url-pattern>/servlets</url-pattern>
  </servlet-mapping>
</web-app>

after I create a .war called servlets.war and put it inside the autodeploy dir of the GlassFish server.

After I point the url: localhost:8080/servlets/helloworld but I have a 404 error.

Why? What's worng?

Thanks.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
xdevel2000
  • 20,780
  • 41
  • 129
  • 196

2 Answers2

6

Hit /yourApplicationContext/servlets as you specified that in url-mapping

for example : http://localhost:8080/myapp/servlets

jmj
  • 237,923
  • 42
  • 401
  • 438
  • Yes, it works. So my confusion was because for me url-pattern was the same of context root and so I called servlets/helloworld. But, instead, url-mapping define a url that when linked trigger the servlet specified and the context root is automatically taken by the name of the war file... – xdevel2000 Apr 22 '11 at 15:21
  • Glad to know – jmj Apr 22 '11 at 15:24
  • @Jigar, sorry again I wish to know if my previous comment is correct... Do I understand well? Thanks a lot. – xdevel2000 Apr 22 '11 at 15:27
  • I don't clearly understand your last comment, but what ever you write as URL-Mapping lets say `/XXX` then if you hit `/contextRoot/XXX` the servlet get invoked, I hope this clears up the thing – jmj Apr 22 '11 at 15:29
2

In Netbeans services window you can right click the particular servlet and click Open in browser. It will run the servlet. You can find that particular URL in the address bar.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
prat
  • 21
  • 3