在Eclipse 中创建一个Servlet或者Filter为什么能创建的出来,但部署运行却说找不到Filter和HttpServlet
importjava.io.IOException;importjavax.servlet.RequestDispatcher;importjavax.servlet.S...
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;
import javax.xml.ws.Dispatch;
/**
* Servlet implementation class UserSrv
*/
public class UserSrv extends HttpServlet {
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String a="垃圾处理";
request.setAttribute("a",a);
RequestDispatcher dispatcher=request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
}
}
为什么能新建,类开头那些包也导入了,却不运行呢?
这个是过滤器
package com.test.dao;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
* Servlet Filter implementation class Charactor
*/
public class CharactorEncodFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
chain.doFilter(request, response);
}
}
重启Tomcat就会报:java.lang.NoClassDefFoundError: Filter 展开
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Dispatch;
/**
* Servlet implementation class UserSrv
*/
public class UserSrv extends HttpServlet {
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String a="垃圾处理";
request.setAttribute("a",a);
RequestDispatcher dispatcher=request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
}
}
为什么能新建,类开头那些包也导入了,却不运行呢?
这个是过滤器
package com.test.dao;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
* Servlet Filter implementation class Charactor
*/
public class CharactorEncodFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
chain.doFilter(request, response);
}
}
重启Tomcat就会报:java.lang.NoClassDefFoundError: Filter 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询