Topic: 请求帮助:我的tomcat配置出现了问题不能正常显示servlet |
Print this page |
1.请求帮助:我的tomcat配置出现了问题不能正常显示servlet | Copy to clipboard |
Posted by: seanwang Posted on: 2004-08-16 09:48 目录及文件结构如下: D:\jakarta-tomcat-4.1.29\conf server.xml: <Context path="/DEV" docBase="DEV" debug="0" reloadable="true"/> D:\jakarta-tomcat-4.1.29\webapps\DEV\ch01\WEB-INF\classes web.xml: 将原D:\jakarta-tomcat-4.1.29\conf下的xml文件copy到此目录下添加如下内容 <servlet> <servlet-name>ch01_06</servlet-name> <servlet-class>ch01_06<servlet-calss> </servlet> <servlet-mapping> <servlet-name>ch01_06</servlet-name> <url-pattern>/ch01/ch01_06</url-pattern> </servlet-mapping> 使用此url:http://localhost:8080/DEV/ch01/ch0106 不能访问 我搜了半天,看了手头的几本书还是没有找出解决办法,可能其他初学者也遇到了和我 一样的问题,希望能在这里得到解决 |
2.追加 [Re: seanwang] | Copy to clipboard |
Posted by: seanwang Posted on: 2004-08-16 10:11 要执行得servlet如下: import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ch01_06 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("A Web Page"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("Hello there!"); out.println("</BODY>"); out.println("</HTML>"); } } 出现的错误如下 HTTP Status 404 - /DEV/ch01/ch01_06 -------------------------------------------------------------------------------- type Status report message /DEV/ch01/ch01_06 description The requested resource (/DEV/ch01/ch01_06) is not available. -------------------------------------------------------------------------------- Apache Tomcat/4.1.29 |
3.Re:请求帮助:我的tomcat配置出现了问题不能正常显示servlet [Re: seanwang] | Copy to clipboard |
Posted by: seanwang Posted on: 2004-08-16 11:13 我已将D:\jakarta-tomcat-4.1.29\webapps\DEV\ch01\下的 web.xml修改成如下: <?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> <display-name>My Web Application</display-name> <description> A application for test. </description> <servlet> <servlet-name>ch01_06</servlet-name> <display-name>ch01_06Servlet</display-name> <description>A test Servlet</description> <servlet-class>ch01_06</servlet-class> </servlet> <servlet-mapping> <servlet-name>ch01_06</servlet-name> <url-pattern>/ch01_06</url-pattern> </servlet-mapping> </web-app> 并且修改了server.XML 添加了:<Context path="/sev" docBase="DEV\ch01" debug="0" reloadable="true"/> http://localhost:8080/sev/ch01_06已经可以运行了。 可为什么不加入上条运行http://localhost:8080/DEV/ch01/ch01_06 就不行呢? |
4.请版主删除此贴,我已将它移到了j2ee版了 [Re: seanwang] | Copy to clipboard |
Posted by: seanwang Posted on: 2004-08-16 11:17 |
5.Re:请求帮助:我的tomcat配置出现了问题不能正常显示servlet [Re: seanwang] | Copy to clipboard |
Posted by: dennisjl Posted on: 2004-08-16 15:17 在tomcat中, 我记得自定义的servlet是要加个包才能访问的。比如上例中的类:ch01_06 应该加定义一个包: package web; 或者你可以用在Resin服务器中试一下, 它不会有这个问题。 如果是初学者的话我建议用Resin, 它比tomcat容易配置得多,很多情况下都是不需要配置的。 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |