当前位置:编程学习 > JAVA >>

eclipse上开发jsp时web.xml的问题


首先,可以看一下这个帖子http://bbs.csdn.net/topics/360034379

大概意思就是:在web应用程序目录/WEB-INF/web.xml中并没有自动生成servlet相关元素

然后那位楼主说:

貌似找到原因了:
the app uses the @WebServlet annotation to give URL patterns to servlets, and will only run in Tomcat 7 or other servlet 3.0 containers. It will not run in Tomcat 6. 

而eclipse新建servlet时,会自动在代码中生成@WebServlet annotation!


那我们如果项配置web.xml时怎么办呢?

例如,配置一个


  <servlet>
    <servlet-name>ServletDemo5</servlet-name>
    <servlet-class>com.tiankong.servlet.ServletDemo5</servlet-class>
    
    <init-param>
        <param-name>myParam</param-name>
        <param-value>paramValue</param-value>
    </init-param>
    
  </servlet>


如果自己在下面这个web.xml里配的话,我运行结果是无效


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>ch06</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>



请问,想自己配置web.xml该怎么办?
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,