robinsonZ
2015-10-10 02:30
采纳率: 0%
浏览 3.9k
已采纳

java web无法调用含有@WebServlet("")的java方法

我想问一下,我这样要怎么才能调用src里包里的java方法?

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_2_5.xsd" version="2.5"  metadata-complete="true">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <listener>
    <listener-class>(省略包名).utils.StatisticsContextListener</listener-class>
  </listener>
  <filter>
    <filter-name>charsetfileter</filter-name>
    <filter-class>(省略包名).utils.CharSetFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>charsetfileter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

charsetfilter.java:

 public class CharSetFilter implements Filter {

    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        chain.doFilter(request, response);

    }

    public void init(FilterConfig arg0) throws ServletException {
        System.out.println("init");
    }
}

想调用的方法:
AskShopInfo.java:

 @WebServlet("/AskShopInfo")
public class AskShopInfo extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("AskShopInfo");
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("AskShopInfo");
        doGet(request, response);
    }

}

1条回答 默认 最新

相关推荐 更多相似问题