servlet终于编译成功了,放到G:\tomcat\webapps\ROOT\WEB-INF\CLASSES\Hello但是不能运行,用http://localhost/servlet/HelloWorld访问出

hnzzyagami 2004-11-21 11:28:55

HTTP Status 404 - Servlet HelloServlet is not available

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

type Status report

message Servlet HelloServlet is not available

description The requested resource (Servlet HelloServlet is not available) is not available.


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

Apache Tomcat/5.5.4





*************************************
web.xml
-----------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<!-- JSPC servlet mappings start -->

<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>

<!-- JSPC servlet mappings end -->


<!-- JSPC servlet mappings start -->

<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>Hello.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

<!-- JSPC servlet mappings end -->


</web-app>
******************************************
HelloServlet.java
---------------------------------------------
package Hello;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet 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>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}

已经把conf/web.xml的 invoker打开了 ,但是还是不可以
...全文
202 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hnzzyagami 2004-11-24
  • 打赏
  • 举报
回复
不好意思啦,前几天宽带坏掉了,没有及时结分,请大家见谅。
感谢大家
okitgo 2004-11-22
  • 打赏
  • 举报
回复
恭喜,接分
mazekui 2004-11-22
  • 打赏
  • 举报
回复
恭喜,接分
wandou999 2004-11-22
  • 打赏
  • 举报
回复
up
hnzzyagami 2004-11-22
  • 打赏
  • 举报
回复
终于弄好了,我把package去掉了,然后把类重新编译,方到classes下,把web.xml的类名改了。
终于出来啦,感谢大家。给分,给分。
hnzzyagami 2004-11-22
  • 打赏
  • 举报
回复
感谢各位帮忙,可惜还是不行。
翻阅以前的很多帖子基本上都按照他们的作了。还是不行。
我去找个老一点版本tomcat好了。
hnzzyagami 2004-11-22
  • 打赏
  • 举报
回复
TO: BillyGao(小马)
你说的对 名字弄错了
已经改过来了 变成HelloServlet也一样
TO:rootcn(走的人多了)
我按照你的方法去试验一下,我们这两个文件区别就是顺序。。猛一看是一样的。
看看能不能行
rootcn 2004-11-21
  • 打赏
  • 举报
回复
web.xml
-----------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<!-- JSPC servlet mappings start -->

<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>

<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>Hello.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

<!-- JSPC servlet mappings end -->


</web-app>

这样试一下。
无欲则钢 2004-11-21
  • 打赏
  • 举报
回复
<url-pattern>/servlet/*</url-pattern>
你要以上面的方式去调用
BillyGao 2004-11-21
  • 打赏
  • 举报
回复
你的Servlet名是HelloServlet,但你的请求是HelloWorld,当然出错,404错误,找不到路径,改成HelloServlet就可以了

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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