创建我在tomcat上运行的第一个IntelliJ Web应用程序。
项目运行正常,它使index.jsp很好。
如果web.xml没有对btw的引用,为什么index.jsp会呈现?它首先查找精神文件(.jsp),如果存在,它会执行它们吗?或者是web.xml仅适用于servlet?
真正的问题是我在/ src文件夹中创建了一个TestServlet,它似乎找不到javax.servlet jar:
package javax.servlet.http does not exist
参考:
的web.xml:
<?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_2_5.xsd"
version="2.5">
<servlet>
<display-name>Test1</display-name>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>
</web-app>
TestServlet.java:
import java.io.IOException;
package hello_world.Servlets
/**
* Created by IntelliJ IDEA.
* User: snad
* Date: Oct 29, 2011
* Time: 9:19:27 AM
* To change this template use File | Settings | File Templates.
*/
public class TestServlet extends javax.servlet.http.HttpServlet {
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
}
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
}
}
答案 0 :(得分:3)
test.TestServlet