一个servlet的问题!来者有分!在线等待。

fightplane 2003-11-21 04:07:22

下面是jsp web编程指南上的一个例子,可是我总是调用不成功。
书上让我在tomcat\webapps下先建立begjsp-ch13\WEB-INF\classes\com\wrox\servlets一系列的目录。在begjsp-ch13\WEB-INF\classes\com\wrox\servlets下创建一个ExampleServlet.java的文件。
文件内容如下:

package com.wrox.servlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ExampleServlet extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
PrintWriter out;
String title = "Servlet Example";
response.setContentType("text/html");
out = response.getWriter();
out.println("<html><head><title>");
out.println(title);
out.println("</title></head><body>");
out.println("<h1>This is an example servlet.</h1>");
out.println("</body></html>");
out.close();
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
doGet(request,response);
}
}
编译后在浏览器输入如下路径访问该文件http://localhost:8080/begjsp-ch13/servlet/com.wrox.servlets.ExampleServlet
结果出错提示:
HTTP Status 404 - /begjsp-ch13/servlet/com.wrox.servlets.ExampleServlet

--------------------------------------------------------------------------------

type Status report

message /begjsp-ch13/servlet/com.wrox.servlets.ExampleServlet

description The requested resource (/begjsp-ch13/servlet/com.wrox.servlets.ExampleServlet) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.12
...全文
38 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
fightplane 2003-11-26
  • 打赏
  • 举报
回复
谢谢大家,虽然我按照书让写的没有调试成功.但是我已经有了答案了.
让我想起中国的一句话:即信书,莫若无书.
fightplane 2003-11-25
  • 打赏
  • 举报
回复
<form action="<%=request.getContent()%>\com\wrox\servlets">
试试。。。
这是要做什么呢?不明白
xl5550 2003-11-21
  • 打赏
  • 举报
回复
<form action="<%=request.getContent()%>\com\wrox\servlets">
试试。。。
caodavid2003 2003-11-21
  • 打赏
  • 举报
回复
同: fightplane(冰风) ( ) 的看法
你用http://localhost:8080/begjsp-ch13/com.wrox.servlets.ExampleServlet访问一下试试
wbs0770 2003-11-21
  • 打赏
  • 举报
回复
建议楼主去http://expert.csdn.net/Expert/topic/2426/2426172.xml?temp=.7739374看一下
wbs0770 2003-11-21
  • 打赏
  • 举报
回复
我建议你把环境变量配置一下,至于那个web.xml我没有改一样好用

下面是我机器的环境变量
CLASSPATH:
.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%TOMCAT_HOME%\common\lib\servlet.jar

JAVA_HOME:
D:\j2sdk1.4.2

TOMCAT_HOME:
D:\Tomcat 4.1
fightplane 2003-11-21
  • 打赏
  • 举报
回复
Tomcat5.0.12需要配置你的web.xml,把servlet映射一下
Tomcat4.0.6就不用了

怎么映射啊!?
warriorwww 2003-11-21
  • 打赏
  • 举报
回复
在浏览器输入如下路径访问就可以拉,
http://localhost:8080/begjsp-ch13/servlet/ExampleServlet
fantasyCoder 2003-11-21
  • 打赏
  • 举报
回复
Tomcat5.0.12需要配置你的web.xml,把servlet映射一下
Tomcat4.0.6就不用了
cricketlj 2003-11-21
  • 打赏
  • 举报
回复
配置你的web.xml
以梦为马 2003-11-21
  • 打赏
  • 举报
回复
如果输入http://localhost:8080/begjsp-ch13/ExampleServlet/可以正常显示,
那么,把你的web.xml改成:<web-app/>
然后输入http://localhost:8080/begjsp-ch13/servlet/com.wrox.servlets.ExampleServlet也就能显示了。
以梦为马 2003-11-21
  • 打赏
  • 举报
回复
1.把.java javac 成.class 并放到相应的位置;
2.要有web.xml
fightplane 2003-11-21
  • 打赏
  • 举报
回复
class文件放的位置没有问题。
web.xml文件内容如下
<web-app>

<display-name>A Simple Application</display-name>
<servlet>
<servlet-name>ExampleServlet</servlet-name>
<servlet-class>com.wrox.servlets.ExampleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ExampleServlet</servlet-name>
<url-pattern>/ExampleServlet/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
我输入http://localhost:8080/begjsp-ch13/ExampleServlet/可以正常显示。
clare0peng 2003-11-21
  • 打赏
  • 举报
回复
應該是訪問的路徑有問題
好好的看看吧
程序和配置都沒有問題
freelarry 2003-11-21
  • 打赏
  • 举报
回复
把你的class文件放对位置。一般应该放在你建 的那一大堆的目录里面
fightplane 2003-11-21
  • 打赏
  • 举报
回复
最好说的具体点
fightplane 2003-11-21
  • 打赏
  • 举报
回复
出错是因为没有找到ExampleServle文件
我应该怎么设置?
老土豆T 2003-11-21
  • 打赏
  • 举报
回复
编辑你的web.xml 论坛faq
kookboy 2003-11-21
  • 打赏
  • 举报
回复
我也不懂!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧