Results 1 to 4 of 4
Thread: Servlet basic example
- 03-08-2010, 03:46 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
Servlet basic example
Hi,
i am very new on J2EE and trying to learn servlets by following an example described in this link: Server-side Java: Understanding JavaServer Pages Model 2 architecture - JavaWorld
Unfortunately i am not able to make the example work, i am getting HTTP Status 404 error: The requested resource (/shopping/ShoppingServlet) is not available.
I am using Tomcat.
My directory structure is as follows:
WebContent/EShop.jsp
WebContent/Cart.jsp
WebContent/WEB-INF/classes/shopping/ShoppingServlet.class
WebContent/WEB-INF/classes/shopping/CD.class
WebContent/META-INF
And web.xml which is automatically created by eclipse is as follows :
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>WebDev_2</display-name>
<servlet>
<description>
</description>
<display-name>ShoppingServlet</display-name>
<servlet-name>ShoppingServlet</servlet-name>
<servlet-class>
shopping.ShoppingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ShoppingServlet</servlet-name>
<url-pattern>/ShoppingServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
What is the problem here?
- 03-08-2010, 03:56 PM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Be sure your URL mapping is correct.
Try like:
http://localhost:8080/application_name/ShoppingServlet
Are you getting any info from servlet?
- 03-08-2010, 04:05 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
When i try with http://localhost:8080/WebDev_2/ShoppingServlet
i get the following error:
HTTP Status 405 - HTTP method GET is not supported by this URL
How can i be be sure that my URL mapping is correct?
- 03-08-2010, 10:21 PM #4
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
In your form :
...
...Java Code:<form name="shoppingForm" action="[B]/examples/servlet/ShoppingServlet"[/B] method="POST">
So there is POST not GET and path is
/examples/servlet/ShoppingServlet
not just
/ShoppingServlet
Open ShoppingServlet.java code, find doGet() method and add some
test to console with some
System.out.println("Hi from doGet() !");
just to test it.
So while trying to solve that url mapping
run ShoppingServlet directly
and see if you can hit that doGet() you added and message in console.
That's easiest way to test in whenever you make it.
So first test GET that you make and then test post from that form.
still got problems?
Similar Threads
-
how can i link html+servlet+xml to form servlet
By balachandarr in forum Java ServletReplies: 0Last Post: 04-15-2009, 04:06 PM -
Servlet to Servlet connection through URLConnection
By bsrjavaforum in forum NetworkingReplies: 0Last Post: 04-01-2009, 04:12 PM -
Servlet - apache tomcat/glassfish server shuts down on servlet usage
By StewS in forum Java ServletReplies: 1Last Post: 12-02-2008, 12:23 AM -
Is there any way to transfer the file Streams from one servlet to another servlet .
By HenaPriyadarsini in forum Java ServletReplies: 0Last Post: 08-30-2008, 11:52 AM -
javax.servlet.ServletException: Wrapper cannot find servlet class util.t2
By osval in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 03:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks