栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Tomcat 7一直给我一个404。我在做什么错?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Tomcat 7一直给我一个404。我在做什么错?

您应该将servlet类放在包中。无包servlet是否起作用取决于旧版Tomcat和JVM版本的特定组合。如果您在书/教程中看到此示例,那么它肯定已经过时了。

package com.example;// ...public class Ch1Servlet extends HttpServlet {    // ...}

您应该有一个

/com/example/Ch1Servlet.java
文件。编译如下

javac -classpath /usr/share/tomcat7/common/lib/servlet-api.jar -d classes src/com/example/Ch1servlet.java

(I however wonder what the

common
lib is doing there, this was typical for
Tomcat 4.x/5.x, but it’s not present since Tomcat 6. If you manually changed
Tomcat’s structure in order to follow the instructions of an outdated
tutorial, undo it!)

Put the

com
folder with the generated class by its entirity in
/WEB-INF/classes
folder of your webapp. So you must have a
/WEB-INF/classes/com/example/Ch1Servlet.class
.

Then, edit your

/WEB-INF/web.xml
to specify the fully qualified name (FQN)
of the servlet class in
<servlet-class>
:

<?xml version="1.0" encoding="UTF-8"?><web-app     xmlns="http://java.sun.com/xml/ns/javaee"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"    version="3.0" >    <servlet>        <servlet-name>Chapter1 Servlet</servlet-name>        <servlet-class>com.example.Ch1Servlet</servlet-class>    </servlet>    <servlet-mapping>        <servlet-name>Chapter1 Servlet</servlet-name>        <url-pattern>/Serv1</url-pattern>    </servlet-mapping></web-app>

(please note that I fixed the root declaration as well to comply Tomcat 7
supported servlet version, it would otherwise fall back to least compatibility
modus)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/515515.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号