Tomcat default servlet

每个servlet容器都有一个默认的servlet,一般都叫做default

servletDefault
  
      dummy
      liulixin.DummyServlet
    
    
      dummy
      /dummy
    
    
     
        default
        /static/index.html
    
  
    index.html
    index.htm
    index.jsp
    

package liulixin;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DummyServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request,
                     HttpServletResponse response)
    throws ServletException, IOException
{
	System.out.println("it does come here");
	final String resourcePath = request.getPathTranslated();
    final String requestURI = request.getRequestURI();
    System.out.println("resourcePath "+resourcePath);
    System.out.println("URI "+requestURI);
	//RequestDispatcher requestDispatcher=getServletContext().getNamedDispatcher("default6");
	//上面这种写法报NullPointerException
	RequestDispatcher requestDispatcher=getServletContext().getNamedDispatcher("default");
	System.out.println(requestDispatcher==null);
	requestDispatcher.forward(request, response);
}
}
输出:

it does come here
resourcePath null
URI /servletDefault/dummy
false

源代码:http://pan.baidu.com/share/link?shareid=1256152557&uk=3878681452

你可能感兴趣的:(Jsp)