Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

deploying WARs

hi - i am starting SCWCD study and am having trouble deploying servlets. Using Tomcat 4.1.18 on w2k pro under jdk1.4.1

ide is forte studio 4 U1 and jdev 9 (same problem when using either)

i created a really trivial servlet and a web.xml then deployed the WAR (as webapp1.war) to the webapps folder.

this is the web.xml
<?xml version = '1.0' encoding = 'windows-1252'?>
<!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>
  <description>Empty web.xml file for Web Application</description>
  <servlet>
    <servlet-name>Servlet1</servlet-name>
    <servlet-class>Servlet1</servlet-class>
  </servlet>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
  <mime-mapping>
    <extension>html</extension>
    <mime-type>text/html</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>txt</extension>
    <mime-type>text/plain</mime-type>
  </mime-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

this is servlet1
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;

public class Servlet1 extends HttpServlet
{
     private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

     public void init(ServletConfig config) throws ServletException
     {
          super.init(config);
     }

     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
     {
          response.setContentType(CONTENT_TYPE);
          PrintWriter out = response.getWriter();
          out.println("<html>");
          out.println("<head><title>Servlet1</title></head>");
          out.println("<body>");
          out.println("<p>The servlet has received a GET. This is the reply.</p>");
          out.println("</body></html>");
          out.close();
     }
}
there is also an HTML file at the same level as the WEB-INF folder (which contains the classes folder and within that the servlet class)

i deployed this to the webapps folder as a built WAR and i can browse to the HTML file with http://localhost:8080/webapp1/testhtml.html but http://localhost:8080/webapp1/servlet/Servlet1 fails with a not found error.
if i drop this servlet class into one of the Tomcat example folders, it works, so i know the servlet class isnt corrupt - can anyone give me any advice ?

thanks




0
simonm99
Asked:
simonm99
  • 2
1 Solution
 
NetWizeCommented:
I guess you need a

<servlet-mapping>
  <servlet-name>Servlet1</servlet-name>
  <url-patter>/servlet/Servlet1</url-pattern>
</servlet-mapping>

below the <servlet>.

Another way to solve that would be to enable the Invoker-Servlet in server.xml in your tomcat /conf directory
0
 
simonm99Author Commented:
yes, perhaps - you see the web.xml was generated automatically so I'm learning something here. I'll try it and report, thanks
0
 
simonm99Author Commented:
thanks - i cant find a way to make JDev do this automatically so i'll have to add it manually for now.

i will investiage the invoker-servlet point also.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now