怎麼會出現 Cannot forward after response has been committed???
下面這個是難使用者的servlet:
package com.wdj;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CheckLogin extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
User u=new User();
String path=null;
u.setName(request.getParameter("name"));
u.setPass(request.getParameter("pass"));
if(u.isValidate()){
path="main.jsp";
}else{
path="error.jsp";
}
request.getRequestDispatcher(path).forward(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
this.doGet(request,response);
}
}
下面這個是過濾器;
package com.wdj;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class UserFilter implements Filter{
public void init(FilterConfig congif)throws ServletException{
}
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws IOException,ServletException{
String name=request.getParameter("name");
if(name!=null){
if(name.indexOf("SEX")==-1){
chain.doFilter(request,response);
}else{
System.out.println("error");
request.getRequestDispatcher("error.jsp").forward(request,response);
}
chain.doFilter(request,response);
}else{
chain.doFilter(request,response);
}
}
public void destroy(){
}
}
我一提交表單到servlet中就提示 Cannot forward after response has been committed???
請問我該怎麼改呢,謝謝了,給大家拜個晚年了
package com.wdj;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CheckLogin extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
User u=new User();
String path=null;
u.setName(request.getParameter("name"));
u.setPass(request.getParameter("pass"));
if(u.isValidate()){
path="main.jsp";
}else{
path="error.jsp";
}
request.getRequestDispatcher(path).forward(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
this.doGet(request,response);
}
}
下面這個是過濾器;
package com.wdj;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class UserFilter implements Filter{
public void init(FilterConfig congif)throws ServletException{
}
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws IOException,ServletException{
String name=request.getParameter("name");
if(name!=null){
if(name.indexOf("SEX")==-1){
chain.doFilter(request,response);
}else{
System.out.println("error");
request.getRequestDispatcher("error.jsp").forward(request,response);
}
chain.doFilter(request,response);
}else{
chain.doFilter(request,response);
}
}
public void destroy(){
}
}
我一提交表單到servlet中就提示 Cannot forward after response has been committed???
請問我該怎麼改呢,謝謝了,給大家拜個晚年了
相關文章
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解讀JavaExceptionErrorMIT
- Caused by: java.lang.IllegalStateException: getWriter() has already been called for this responseJavaException
- How To Retry Multiple Errored Approval Workflow Processes After A Fix Or Patch Has Been ImplementedErrorAPP
- PyTorch出現:RuntimeError: An attempt has been made to start a new process...報錯 (已解決)PyTorchError
- RuntimeError: An attempt has been made to start a new process before the current process hasError
- Uncaught SyntaxError: Identifier 'Geometry' has already been declaredErrorIDE
- Thread 1: Fatal error: init(coder:) has not been implementedthreadError
- The app.Configuration 'compile' is obsolete and has been replaced with 'implementation'APPCompile
- 【HMS Core】ToolKit,Merchant Service has not been enabled yet
- Transaction rolled back because it has been marked as rollback-only
- FeignClientSpecification‘ could not be registered. A bean with that name has already been definedclientBean
- has been blocked by CORS policy跨域問題解決BloCCORS跨域
- After Effects出現“最後日誌訊息報警”該怎麼解決
- springcloudconfig訪問gitee報錯:Authentication is required but no CredentialsProvider has been registeredSpringGCCloudGiteeUIIDE
- [原創] How to pull code when shared repo commit history has been changedMIT
- Syntax Error: ValidationError: Invalid options object. Stylus Loader has been initialized using anErrorObjectZed
- PHP Warning: exec() has been disabled for security 問題解決辦法PHP
- 無法啟動homestead,出現報錯Your VM has become "inaccessible." 該怎麼辦?
- BUG記錄-Sharing is only supported for boot loader classes because bootstrap classpath has been appendebootAPP
- Error: php@8.0 has been disabled because it is a versioned formula! It was disabled on 2023-11-29.ErrorPHPORM
- prettier Unexpected closing tag "p". It may happen when the tag has already been closed by another tag.APP
- Android gradle問題解決: This app has been built with an incorrect configuration. Please configure your b...AndroidGradleAPPUI
- Android Studio 出現“Cannot resolve symbol” 解決辦法AndroidSymbol
- react-解決 fetch 跨域問題:Access to fetch at XXX from origin YYY has been blocked by CORS policyReact跨域BloCCORS
- pytorch實現yolov3(3) 實現forwardPyTorchYOLOForward
- IDEA出現Cannot resolve symbol “xxx”(無法解析符號)IdeaSymbol符號
- 什麼情況下會出現css阻塞?CSS
- 什麼情況下會出現js阻塞?JS
- 歡迎收看 Flink Forward Asia 2021 峰會直播Forward
- 騰訊會議怎麼看進出時間
- vue專案啟動報錯(SyntaxError: Identifier ‘__vite__injectQuery’ has already been declared (at ${mod.id}:55030:1))VueErrorIDEVite
- 為什麼網站伺服器會出現500錯誤程式碼?該怎麼修復?網站伺服器
- 使用req.session.xxx時出現 Cannot set property ‘xxxx‘ of undefinedSessionUndefined
- 求助,怎麼修改 response 響應中的 Cookie 的屬性值Cookie
- mac桌面出現白條怎麼解決Mac
- 備忘錄:SQL SERVER2014 出現:“Cannot find one or more components”SQLServer
- This request has been blocked; the content must be served over HTTPS.此請求已被阻止;內容必須透過HTTPS提供BloCHTTP
- Django Mysql SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTEDDjangoMySqlSessionMIT
- win10怎麼設定出廠設定 win10恢復出廠設定會怎麼樣Win10