有关servlet的小案例
protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		System.out.println("username:"+username);
		System.out.println("password:"+password+"\n"+request.getContextPath());
		if(username == null || username == ""){
			response.sendRedirect("http://localhost:8090/webHomework");
		}
		
		if("admin".equals(username) && "admin".equals(password)){
			System.out.println("用户名非空");
			request.getRequestDispatcher("/pages/menu.jsp").forward(request, response);
		}
		System.out.println("*****************");
		super.doGet(request, response);
	}

会提示错误

严重: Servlet.service() for servlet [UserServlet] in context with path [/webHomework] threw exception
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
	at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:450)
	at javax.servlet.http.HttpServlet.doGet(HttpServlet.java:174)
	at com.sinovate.servlet.UserServlet.doGet(UserServlet.java:28)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
如果把super.doGet(request, response);注释掉,程序运行就完全没问题,super.doGet(request, response);不是自动生成的吗,为什么还会出问题呢
?欢迎指点
阅读更多
文章标签: java
个人分类: java
想对作者说点什么? 我来说一句

Ajax和servlet数据交互小实例

2017年07月22日 80KB 下载

java servlet 最简单的小例子

2018年01月19日 8KB 下载

小程序增删改查代码

2018年03月05日 492KB 下载

没有更多推荐了,返回首页

不良信息举报

有关servlet的小案例

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭