- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我的应用程序启动页面加载时收到以下错误:
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...
当我将 css 应用到我的主页时出现此错误,当我删除 css 模板时错误消失(但我想应用 css 模板)以下是导致错误的bean代码片段(调试发现)
public List<MasterScrip> getScripList() {
HttpServletRequest req=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); //error line
HttpSession session=req.getSession();
type=(String)session.getAttribute("type");...
xhtml代码:
<h:body>
<ui:composition template="commonClientLayout.xhtml">
<ui:define name="contentFile">
<div id="content">
<h:form id="frm">...
当我删除 ui:composition 并定义标签时(即,如果我不应用 css),则不会出现此错误。是什么导致了这个错误,我该如何解决?
编辑:
@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;
}
再次编辑:
SEVERE: Error Rendering View[/equityVolume.xhtml]
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:275)...
编辑: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>
最佳答案
你不应该在 setter/getter 中做生意。改为在 bean(后)构造函数中执行。
你的具体问题是因为你在一个全新的浏览器 session 中请求一个相对较大的页面,而服务器 HttpSession
尚未创建并且 EL 表达式 #{ equityBean.scripList
在页面的后面被引用。
响应缓冲区默认为 2KB,当响应过大而溢出时,将提交。这意味着将发送所有响应 header ,并且将发送 HTML 输出的前 ~2KB。然后,在那之后,EL 表达式 #{equityBean.scripList}
将在您尝试获取 session 的位置解析。如果此时尚未创建服务器 HttpSession
,则服务器需要在响应 header 中设置一个 cookie,以便为后续请求维护它。但如果响应已经提交,那当然是不可能的。因此这个异常(exception)。
如前所述,只需在 bean 的(后)构造函数中完成这项工作即可。或者只是将其作为托管属性注入(inject)。
@ManagedProperty("#{type}")
private String type;
如果异常仍然出现,您可能使用的是旧版本的 Mojarra,它存在问题 2215 中描述的错误。和 2277这是由于“不必要的” session 创建过于极度推迟造成的。自 Mojarra 2.1.8 以来已修复此问题。因此,升级到它或更新版本(目前为 2.1.9)应该可以。
与具体问题无关,顺便说一句,getScripList()
逻辑很臭。但这是另一个问题/问题的主题。您知道您可以在 EL 中以 #{type}
访问名称为“type”的 session 属性吗?您是否知道在 JSF 支持 bean 类中导入原始 javax.servlet.*
经常表明您可能以错误的方式做事并且可能有更多“JSF-ish”如何实现具体的功能需求?
关于java - 提交响应后无法创建 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10949556/
是否为每个 Shiny session 分配了 session ID/ session key (如果部署在 Shiny 服务器上)?如果是,我如何访问该信息?我已阅读文档here然而上网查了一下,并
我正在使用 this koajs session 模块。 我检查了源代码,但我真的无法理解。 我想知道它保存 session 数据的位置,因为我没有看到创建的文件,并且当服务器重新启动时, sessi
实现高可扩展性的一种方法是使用网络负载平衡在多个服务器之间分配处理负载。 这种方法提出的一个挑战是服务器是否具有状态意识 - 将用户状态存储在“ session ”中。 此问题的一个解决方案是“粘性
在负载平衡服务器的上下文中, session 亲和性和粘性 session 之间有什么区别? 最佳答案 我见过这些术语可以互换使用,但有不同的实现方式: 在第一个响应中发送 cookie,然后在后续响
我希望其他人向我解释哪种方法更好:使用 session 或设计无 session 。我们正在开始开发一个新的 Web 应用程序,但尚未决定要遵循什么路径。 无 session 设计在我看来更可取: 优
现在用户在他的权限中有很多角色,我将允许他点击 href 并在新窗口中扮演另一个角色。每个角色都有自己的 session 。 既然浏览器打开窗口不能用新 session 打开,我必须在服务器端想办法。
我正在尝试为express.js Node 应用程序实现 session 存储我的问题是: 如何删除具有浏览器 session 生命周期的 cookie(根据连接文档标记有 expires = fal
在开始在 golang 中使用 session 之前,我需要回答一些问题 session 示例 import "github.com/gorilla/sessions" var store = ses
我读过 Namespaced Attributes . 我尝试使用此功能: #src/Controller/CartController.php public function addProduct(
我正在努力完成以下工作: 根据用户的类型更改用户的 session cookie 到期日期。 我有一个 CakePHP Web 应用程序,其中我使用 CakePHP session 创建了我的身份验证
这是我在这里的第一个问题,我希望我做对了。 我需要处理一个 Java EE 项目,所以在开始之前,我会尝试做一些简单的事情,看看我是否能做到。 我坚持使用有状态 session Bean。 这是问题:
ColdFusion session 与 J2EE session 相比有什么优势吗? ColdFusion session documentation提到了 J2EE session 的优点,但没有
在执行任何任务之前,我需要准确地在创建 session 时创建一个 session 范围变量(因为我的所有任务都需要一个初始 session 范围变量才能运行)。因为,创建 session 时,gra
我们当前的应用使用 HTTP session ,我们希望将其替换为 JWT。 该设置仅允许每个用户进行一次 session 。这意味着: 用户在设备 1 上登录 用户已在设备 1 上登录(已创建新 s
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
假设我在两个或更多设备上打开了两个或更多用户 session (同一用户没有管理员权限)。 在当前 session 中,如果我注销,是否意味着所有其他 session 也会关闭?如果没有,有没有办法通
我正在评估在 tomcat 中使用带有 session 复制的粘性 session 的情况。根据我的初步评估,我认为如果我们启用 session 复制,那么在一个 tomcat 节点中启动的 sess
我开始使用 golang 和 Angular2 构建一个常规的网络应用程序,最重要的是我试图在 auth0.com 的帮助下保护我的登录.我从 here 下载快速入门代码并尝试运行代码,它运行了一段时
我在 Spring Controller 中有一个方法,它接受两个相同类型的参数其中一个来自 session ,另一个来自表单提交(UI)。 问题是在 Controller 方法中我的非 sessio
在我登录之前,我可以点击我的安全约束目录之外的任何内容。如果我尝试转到安全约束目录内的某个位置,它会将我重定向到表单登录页面。如您所料。 登录后,我可以继续我的业务,并访问我的安全约束内外的资源。
我是一名优秀的程序员,十分优秀!