Tomcat已经配置成功。以下是配置的内容:C:\wileyapp\chapter2\SimpleServlet.classG:\Tomcat 5.0\webapps\wileyapp\WEB-INF\classes\chapter2\SimpleServlet.classG:\Tomcat 5.0\webapps\wileyapp\WEB-INF\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">
<display-name>My Web Application</display-name>
<description>A application for test.</description>
<web-app>
<display-name>SimpleServlet</display-name>
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>chapter2.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/SimpleServlet</url-pattern>
</servlet-mapping>
</web-app>SimpleServlet.java:
package chapter2;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SimpleServlet extends HttpServlet {
public void init(ServletConfig config)
throws ServletException {
// Always pass the ServletConfig object to the super class
super.init(config);
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Simple Servlet</title></head>");
out.println("<body>");
// Outputs the address of the calling client
out.println("Your address is " + request.getRemoteAddr()
+ "\n");
out.println("</body></html>");
out.close();
}
}打开http://localhost:8080/wileyapp/chapter2/SimpleServlet
报错:
HTTP Status 404 - /wileyapp/chapter2/SimpleServlet--------------------------------------------------------------------------------type Status reportmessage /wileyapp/chapter2/SimpleServletdescription The requested resource (/wileyapp/chapter2/SimpleServlet) is not available.
--------------------------------------------------------------------------------Apache Tomcat/5.0.30
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<display-name>My Web Application</display-name>
<description>A application for test.</description>
<web-app>
<display-name>SimpleServlet</display-name>
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>chapter2.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/SimpleServlet</url-pattern>
</servlet-mapping>
</web-app>SimpleServlet.java:
package chapter2;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SimpleServlet extends HttpServlet {
public void init(ServletConfig config)
throws ServletException {
// Always pass the ServletConfig object to the super class
super.init(config);
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Simple Servlet</title></head>");
out.println("<body>");
// Outputs the address of the calling client
out.println("Your address is " + request.getRemoteAddr()
+ "\n");
out.println("</body></html>");
out.close();
}
}打开http://localhost:8080/wileyapp/chapter2/SimpleServlet
报错:
HTTP Status 404 - /wileyapp/chapter2/SimpleServlet--------------------------------------------------------------------------------type Status reportmessage /wileyapp/chapter2/SimpleServletdescription The requested resource (/wileyapp/chapter2/SimpleServlet) is not available.
--------------------------------------------------------------------------------Apache Tomcat/5.0.30
解决方案 »
- 请帮忙分析一下java.lang.IndexOutOfBoundsException: Index: 0, Size: 0有什么错误?
- Hibernate Dialect must be explicitly set的异常
- 异常捕获问题!!!
- 大家好,请问用jsp怎么做出这个网业上的导行栏的效果(超级技术问题讨论,很难的,高手请进)
- 我是初学者,遇到了一个关于javabean的怪事,期望大家予以解释。
- 使用retroguard混淆器后,得到的新文件jar怎么才能使用???为什么不能用jar文件了???
- 请教:我想在JSP里向指定目录里创建一个XML文件并写进我的东西???
- 简单问题关于"Href":在线
- JavaBean中跳转页面的问题
- jsp配置驱动怎么弄啊!!!
- struts配置问题--有些莫名奇妙
- 请教:如何捕捉到HttpSession丢失 谢谢
这样吧
就是URI/application-name/url-pattern,注意url-pattern要与web.xml中的一致!
---------------------------------------------------------------------------------
试了,还是不行。如果你配置的站点wileyapp在其他路径的wileyapp文件夹下,路径则是:\wileyapp\WEB-INF\classes\chapter2\SimpleServlet.class
---------------------------------------------------------------------------------
没看明白这句话的意思。http://localhost:8080/wileyapp/SimpleServlet
这样吧
---------------------------------------------------------------------------------
任何相关的IP我都尝试过,都有毛病。把URL前面那些去掉,直到ContextPath
---------------------------------------------------------------------------------
您说的去掉那些,具体是去掉哪些啊?还有,ContextPath是啥东东啊?http://localhost:8080/wileyapp/SimpleServlet 楼上说的对!是这样的!
---------------------------------------------------------------------------------
想不通,难道包名不写吗?如果有大量的jsp文件,需要放在N个不同的包里,怎么办?http://localhost:8080/wileyapp/SimpleServlet
就是URI/application-name/url-pattern,注意url-pattern要与web.xml中的一致!
---------------------------------------------------------------------------------
是一致的啊!难道不一致吗?<url-pattern>/SimpleServlet</url-pattern>
并重新启动web服务
---------------------------------------------------------------------------------
试了,还是不行。把两个文件放入上面文件夹后
用这个访问应该就没问题了http://localhost:8080/SimpleServlet
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>chapter2.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/SimpleServlet</url-pattern>
</servlet-mapping>
这段xml的意义 <url-pattern>/SimpleServlet</url-pattern> 表示这个servlet 访问路径http://127.10.0.1:8080/context_name/ SimpleServlet
这里的context_name表示servlet所在的web应用程序的名字
也就是wileyapp建议看看tomcat的有关context配置和web.xml的规范!!
打开http://localhost:8080/wileyapp/SimpleServlet
这样就对了
或者:<url-pattern>/wileyapp/SimpleServlet</url-pattern>http://localhost:8080/wileyapp/SimpleServlet