我使用ajax调用servlet,并在将其部署到websphere时获得以下异常。但它正在我的本地机器上工作。据我所知document,原因是因为我试图同时访问response.getWriter()
和response.getOutputStream()
方法,但事实并非如此,因为我只有getWriter
我的代码中的方法。
我已经在stackoverflow上搜索了以前的问题,但它没有帮助。
所以任何帮助都会受到赞赏
我的Servlet代码
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String[] userStates = request.getParameterValues("user");
String r_object_id = request.getParameter("queueId");
boolean isUpdateSuccessfull =false;
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//ArrayList
//string[0] -> skill_id
//string[1] -> r_object_id
//string[2] -> original_value
ArrayList<String[]> updateList = new ArrayList<String[]>();
for (int i = 0; i < userStates.length; i++) {
String[] update = userStates[i].split("_");
updateList.add(update);
}
try{
DefineSkillSet dss = new DefineSkillSet();
HashMap<String, ArrayList<String>> userSkillMap = new HashMap<String, ArrayList<String>>();
for(String[] status: updateList){
if(status == null && status.length != 2){
// TODO error logging
HlkUtils.printErr(null, "skillSetName()", "status dizisinin boyutu yanlış");
continue;
}
// get array values
String skillId = status[0];
String objectId = status[1];
// check if object ID exists in hash map
if(!userSkillMap.containsKey(objectId)){
ArrayList<String> skillList = new ArrayList<String>();
skillList.add(skillId);
userSkillMap.put(objectId, skillList);
}
else{
userSkillMap.get(objectId).add(skillId);
}
}
isUpdateSuccessfull = dss.Update(userSkillMap, r_object_id);
}
catch(Exception e){
e.printStackTrace();
}
if(isUpdateSuccessfull){
response.getWriter().write("Güncelleme Başarılı");
}
else{
response.getWriter().write("Güncelleme Yapılamadı!");
}
}
我的错误日志
[4/20/15 9:41:27:795 EEST] 00000128 webapp E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[dispatcherServlet]: java.lang.IllegalStateException: Cannot forward. Response already committed.
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1148)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:193)
at org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler.handleRequest(DefaultServletHttpRequestHandler.java:120)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.__AW_service(HttpServlet.java:668)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1225)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:775)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:457)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at com.emc.xcp.rest.security.filter.BasicAuthFilter.doFilter(BasicAuthFilter.java:51)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at com.emc.xcp.rest.security.filter.CSRFTokenFilter.doFilter(CSRFTokenFilter.java:23)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.__AW_doFilter(LogoutFilter.java:105)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.__AW_doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at com.emc.xcp.rest.security.filter.RepositoryInfoFilter.doFilter(RepositoryInfoFilter.java:33)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at com.emc.xcp.ui.LocaleFilter.doFilter(LocaleFilter.java:26)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at com.emc.xcp.ui.web.filter.CustomCharEncodingFilter.doFilterInternal(CustomCharEncodingFilter.java:47)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3761)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:975)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:459)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:526)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:312)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:87)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1815)
[4/20/15 9:41:27:811 EEST] 00000128 srt W com.ibm.ws.webcontainer.srt.SRTServletResponse setStatus WARNING: Cannot set status. Response already committed.
[4/20/15 9:41:27:811 EEST] 00000128 srt W com.ibm.ws.webcontainer.srt.SRTServletResponse addHeader SRVE8094W: WARNING: Cannot set header. Response already committed.
修改
事实证明我有一个servlet映射问题。错误日志说
Error while adding servlet mapping for path-->/UpdateSkillSet, wrapper-->ServletWrapper[com.hlk.katip.skillset.UpdateSkillSet:[/UpdateSkillSet]], application-->Katip_BPM.
在我的本地计算机上,我的网址为 - http://localhost:8080/KatipSkillSetWeb/skillset.jsp
我的servlet映射是
<servlet>
<servlet-name>UpdateSkillSet</servlet-name>
<servlet-class>com.hlk.katip.web.skillset.UpdateSkillSet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UpdateSkillSet</servlet-name>
<url-pattern>/UpdateSkillSet</url-pattern>
</servlet-mapping>
现在我在服务器上的网址是 - http://gtdctmdapp01:9084/Katip_BPM/skillset/skillset.jsp
我的servlet映射再次是
<servlet>
<servlet-name>UpdateSkillSet</servlet-name>
<servlet-class>com.hlk.katip.web.skillset.UpdateSkillSet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UpdateSkillSet</servlet-name>
<url-pattern>/UpdateSkillSet</url-pattern>
</servlet-mapping>
所以可能在服务器上我的url-pattern应该是/ skillset / UpdateSkillSet
答案 0 :(得分:1)
er.webapp.WebApp logServletError SRVE0293E:[Servlet 错误] - [dispatcherServlet]:java.lang.IllegalStateException:不能 向前。响应已经提交。
错误很明显。您已将输出写入响应流,并且某处的过滤器正在尝试将请求转发到另一个资源。
我可以在堆栈跟踪中看到的自定义类的第一个实例是以下
com.emc.xcp.rest.security.filter.BasicAuthFilter.doFilter(BasicAuthFilter.java:5 1)
如果那不是你的类,你使用的框架使用那个你应该开始调试的过滤器类。
答案 1 :(得分:0)
您的代码中出现了一些错误,该错误在try-catch块中捕获,您在其中编写了e.printStackTrace(),因此它将写入输出流。缓存后,您正在使用getWriter编写一些内容。