我在我的web.xml文档中有这个东西。 我正在尝试拥有一个欢迎列表,以便我不再需要键入主页的路径。 但是每次我在tomcat页面上单击应用程序时,它会显示“所请求的资源不可用”。
<listener>
<listener-class>web.Init</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>index</servlet-name>
<servlet-class>web.IndexServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
我的servlet用于jsp页面
package web;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
public class IndexServlet extends HttpServlet
{
private Logger logger = Logger.getLogger(this.getClass());
private RequestDispatcher jsp;
public void init(ServletConfig config) throws ServletException
{
ServletContext context = config.getServletContext();
jsp = context.getRequestDispatcher("/WEB-INF/jsp/index.jsp");
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
logger.debug("doGet()");
jsp.forward(req, resp);
}
}
为什么它还是不工作?我仍然需要在URL中输入/index...应该如何正确操作?