我有这个我的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>
我的JSP页面的servlet
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);
}
}
为什么它仍然没有工作?我还需要在我的网址键入/指数...如何正确地做到这一点?