Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic Servlet question

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have servlet called :TestServlet

It is in the package ackage brokearage.broker.co.servlet.broker;

In my web.xml I have the 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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<display-name>TestServlet</display-name>
<description>TestServlet</description>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>brokearage.broker.co.servlet.broker.TestServlet</servlet-class>
</servlet>
</web-app>

Its jarred into a war file BrokerWar.war.

two questions how would I call TestServlet from a JSP and directly from a URL

I know this ia a basic question but I have spent all afternoon trying to access my servlet.

Thanks for any help

Tony
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set up a servlet mapping in the deployment descriptor (web.xml).

Here's an example:



Assuming that the web app context path is /xyz, the URL to the servelt would be:

http://myserver.com/xyz/someServlet

If the web app is mapped to the root context, omit the /xyz.

P.S. Also, when posting code, be sure to use the UBB code tags to preserve the formatting.
[ July 19, 2006: Message edited by: Bear Bibeault ]
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for anyone else interested I now have in my web.xml the 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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<display-name>TestServlet</display-name>
<description>TestServlet</description>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>brokearage.broker.co.servlet.broker.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/testServlet</url-pattern>
</servlet-mapping>
</web-app>

And call it with

http://localhost:11001/BrokerWAR/testServlet
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume your servlet is running fine now.

Also, if you are adding another Servlet in you web.xml file, keep your servlet and servlet mapping segregated.

For Example,
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>s1<</servlet-class>
</servlet>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>s2<</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/s1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>/s2</url-pattern>
</servlet-mapping>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic