tôi đang nhận được lỗi sau trên ứng dụng tải trang khởi động của tôi:không thể tạo phiên sau khi phản ứng đã được cam kết
SEVERE: Error Rendering View[/HomeTemplate/equityVolume.xhtml]
javax.el.ELException: /HomeTemplate/equityVolume.xhtml @70,78 value="#{equityBean.scripList}": java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed...
Caused by: java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed...
tôi nhận được lỗi này khi tôi áp dụng css để trang chủ của tôi, lỗi biến mất khi tôi loại bỏ template css (nhưng tôi muốn aplly mẫu css) sau đây là đoạn mã đậu gây ra lỗi (tìm thấy bằng cách gỡ lỗi)
public List<MasterScrip> getScripList() {
HttpServletRequest req=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); //error line
HttpSession session=req.getSession();
type=(String)session.getAttribute("type");...
mã xhtml:
<h:body>
<ui:composition template="commonClientLayout.xhtml">
<ui:define name="contentFile">
<div id="content">
<h:form id="frm">...
khi tôi xóa thành phần ui: bố cục và xác định thẻ (ví dụ: nếu tôi không áp dụng css), sau đó tôi không nhận được lỗi này. điều gì có thể gây ra lỗi này và làm cách nào để giải quyết?
chỉnh sửa:
@PostConstruct
void initialiseSession() {
if(type!=null)
{
if(type.equalsIgnoreCase("losers"))
{
scripList=new ArrayList<MasterScrip>();
scripList=getScripByPriceLosers(exchange);
// return scripList;
}
else if(type.equalsIgnoreCase("gainers"))
{
scripList=new ArrayList<MasterScrip>();
scripList=getScripByPriceGainers(exchange);
// return scripList;
}
else
{
scripList=new ArrayList<MasterScrip>();
scripList=getScripByVolumeType(exchange);
// return scripList;
}
}
else
{
scripList=new ArrayList<MasterScrip>();
scripList=getScripByVolumeType(exchange);
}
}
public List<MasterScrip> getScripList() {
return scripList;
}
sửa lại:
SEVERE: Error Rendering View[/equityVolume.xhtml]
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:275)...
chỉnh sửa: web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
<param-value>65535</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>equityVolume.xhtml</welcome-file>
</welcome-file-list>
<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>AdminTemplate</web-resource-name>
<description/>
<url-pattern>/AdminTemplate/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>Constraint2</display-name>
<web-resource-collection>
<web-resource-name>ClientTemplate</web-resource-name>
<description/>
<url-pattern>/ClientTemplate/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>client</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>DataRealm</realm-name>
<form-login-config>
<form-login-page>/equityVolume.xhtml</form-login-page>
<form-error-page>/errorpage.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description/>
<role-name>admin</role-name>
</security-role>
<security-role>
<description/>
<role-name>client</role-name>
</security-role>
</web-app>
cảm ơn vì đã giải thích. I đặt logic nghiệp vụ trong phương thức postConstruct, tôi vẫn gặp lỗi tương tự (xem câu hỏi đã chỉnh sửa). Tôi không thể có thêm bất kỳ thứ gì trong ứng dụng của mình nữa, tôi nên làm gì ?:( – z22
Vì vậy, bean đơn giản là không được tham chiếu ở bất kỳ đâu trong trang? JSF impl/version nào bạn đang sử dụng? Một vấn đề tương tự đã được sửa trong Mojarra 2.1.8. Hoặc bạn có thể thay đổi và tăng kích thước bộ đệm phản hồi mặc định – BalusC
có nó được tham chiếu trước đó trong trang xhtml – z22