在我在tomcat 7上运行的grails应用程序中,某处我无效现有的http session(session.invalidate())并创建一个新的session(request.getSession(true)).
但我的这个新会议并没有在grails应用程序中随处反映出来.因此我得到' Session already invalidated'.
我不想request.getSession()到处做.我只是在使用'session'.
Grails 1.3.7中有什么内容,所以这个新会话会反映在应用程序的每个位置.
如果您需要更多信息,请告诉我.
问候
Laerer laerer = (Laerer) session.getAttribute("laererInnlogget");
List<Spoerreskjema> ss = laerer.getSkjemaliste();
if(ss == null)
System.out.println("1");
if(ss != null)
System.out.println("2");
if(ss.isEmpty())
System.out.println("3");
if(!ss.isEmpty())
System.out.println("4");
Run Code Online (Sandbox Code Playgroud)
if循环用于显示问题所在.
控制台将显示2,然后在到达ss.isEmpty()时抛出NullPointerException
laerer对象不为null,但包含一个应为null(或至少为空)的List
所有这些都存储在postgresql数据库中或从postgresql数据库中获取.
知道问题可能是什么?
顺便说一句,调用ss.size()也会导致NullPointerException
我本质上希望能够检查列表是否为空.
SEVERE: Servlet.service() for servlet [no.hib.prosjekt01.controllers.laerer.LaererHjemServlet] in context with path [/prosjekt01] threw exception
java.lang.NullPointerException
at org.apache.openjpa.enhance.no$hib$prosjekt01$models$Laerer$pcsubclass.pcReplaceField(Unknown Source)
at org.apache.openjpa.kernel.StateManagerImpl.replaceField(StateManagerImpl.java:3254)
at org.apache.openjpa.kernel.StateManagerImpl.storeObjectField(StateManagerImpl.java:2681)
at org.apache.openjpa.kernel.StateManagerImpl.storeObject(StateManagerImpl.java:2671)
at org.apache.openjpa.jdbc.meta.strats.StoreCollectionFieldStrategy.load(StoreCollectionFieldStrategy.java:596)
at org.apache.openjpa.jdbc.meta.FieldMapping.load(FieldMapping.java:934)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:681)
at org.apache.openjpa.kernel.DelegatingStoreManager.load(DelegatingStoreManager.java:117)
at org.apache.openjpa.kernel.ROPStoreManager.load(ROPStoreManager.java:78)
at org.apache.openjpa.kernel.StateManagerImpl.loadFields(StateManagerImpl.java:3146)
at org.apache.openjpa.kernel.StateManagerImpl.loadField(StateManagerImpl.java:3226)
at org.apache.openjpa.kernel.StateManagerImpl.fetchObjectField(StateManagerImpl.java:2468)
at org.apache.openjpa.kernel.StateManagerImpl.fetchField(StateManagerImpl.java:890)
at org.apache.openjpa.kernel.StateManagerImpl.fetch(StateManagerImpl.java:852)
at org.apache.openjpa.enhance.RedefinitionHelper$1.invoke(RedefinitionHelper.java:230)
at com.sun.proxy.$Proxy68.isEmpty(Unknown Source)
at no.hib.prosjekt01.controllers.laerer.LaererHjemServlet.doGet(LaererHjemServlet.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at …Run Code Online (Sandbox Code Playgroud) 我在Tomcat服务的Web应用程序中遇到Session超时有点麻烦.通过阅读Tomcat的文档,会话可以在web.xml文件中配置一段时间后到期.
<session-config>
<session-timeout>30</session-timeout>
</session-config>
Run Code Online (Sandbox Code Playgroud)
Quesion)这是否意味着从为用户创建会话的30分钟后?或者从上次访问会话开始30分钟?
如果是,正如我原先想的那样,从上次访问会话开始的30分钟后,我似乎没有看到这种行为.当我使用该网站时,我的会话似乎丢失了.除了这一个设置之外,还有其他方法可以配置会话行为吗?有什么我想念的吗?
Apache Tomcat/6.0.20
我在我的服务器应用程序中使用 HttpSession。并为会话设置属性。接下来我的问题是:会话属性如何设置 - 通过引用或值。
问题在于担心不会出现 java 堆空间异常和 RAM 节省。
例如:如果我将创建无状态array1并将其设置为不同会话的属性。在这种情况下,所有会话都将作为“单例”实例运行array1,也可能不运行
谢谢!
我接受了一个JSP类,我们了解到在使用之前我们应该总是删除HttpSession的所有属性.所以我的一位同学问道 - "我们在使用它之后永久删除HttpSession怎么样?"
所以,我的问题是"可以删除HttpSession吗?"
从我到目前为止的理解...... HttpSession是由servlet容器创建的,与HttpServletRequest和HttpServletResponse相同.我们通过HttpServletRequest获取它,但是我们不能手动删除它.相反,我们可以设置超时以使会话结束.由于我们无法删除它,因此我们需要确保在使用之前清理会话.我对么?
谢谢!
我正在尝试使用服务器URL将图像上传到服务器.为此,我使用java.netapi.发送请求后,它返回一个显示会话无效的响应.我从该服务器获取会话ID但无法添加它.如何HttpURLConnection在向服务器发送请求时使用添加会话ID .他们有什么方法可以解决这个问题?
在我的Struts应用程序中,一旦用户登录,我需要使当前会话无效并创建新会话.我用会话使会话无效
getHttpServletRequest().getSession().invalidate();
Run Code Online (Sandbox Code Playgroud)
我创建了一个新会话
getHttpServletRequest().getSession(true);
Run Code Online (Sandbox Code Playgroud)
这里的问题是上面我尝试访问getSession()它后给出状态无效异常; HttpSession是无效的.
getSession()返回一个地图,在我的动作类中我实现了SessionAware哪个有setSession(Map session).
编辑:以下是例外
Error creating HttpSession due response is commited to client. You can use the CreateSessionInterceptor or create the HttpSession from your action before the result is rendered to the client: HttpSession is invalid
java.lang.IllegalStateException: HttpSession is invalid
Run Code Online (Sandbox Code Playgroud)
所以,我认为问题是Struts getSession()仍然引用我已经失效的会话.
如何让Struts getSession()引用我创建的新会话?
我在jsp页面中使用jqueryui 自动完成组合框。我需要将组合框的选定值设置为.HttpSession
我尝试如下。
this._on(this.input, {
autocompleteselect: function (event, ui) {
// alert(ui.item.value);
var value = ui.item.value;
<% session.setAttribute("comboboxvalue",value); %>
ui.item.option.selected = true;
this._trigger("select", event, {
item: ui.item.option
});
}
Run Code Online (Sandbox Code Playgroud)
这种方式的问题是代码无法识别value参数。
我该如何解决这个问题并使用设置会话属性javascript?
我刚刚尝试在我的测试Web应用程序中添加会话侦听器HttpSessionBindingListener和HttpSessionAttributeListener ; 它们都在我的测试对象中实现为:
public class MySessionListener implements HttpSessionBindingListener,HttpSessionAttributeListener
{
//implemented methods...
}
Run Code Online (Sandbox Code Playgroud)
事情是...
我试过像一个代码
session.setAttribute("name",new TestValue());
Run Code Online (Sandbox Code Playgroud)
因此,我希望调用HttpSessionBindingListener事件,valueBound(...)但我只调用了HttpSessionAttributeListener一个attributeAdded(...):(
而且,关于valueUnbound(...)方法态度与我提到的完全相同,我使用的代码就像
session.removeAttribute("name");
Run Code Online (Sandbox Code Playgroud)
...但我attributeRemoved(...)只是被称为同一个:S
我想尝试putValue()方法,但现在我正在观看HttpSession文档,其中说"putValue已弃用.从版本2.2开始,此方法被setAttribute(java.lang.String,java.lang.Object)取代"
所以我不知道为什么调用valueBound(...)或valueUnbound(...)不调用以及如何调用它们?
谢谢
亲爱的,我正在尝试在我的 WebSocketHandler 中获取 HTTPSession。当我使用“javax.websocket-api”时我可以成功完成此操作,但我现在使用“Spring-Websocket”。
配置:
@ConditionalOnWebApplication
@Configuration
@EnableWebSocket
public class WebSocketConfigurator implements WebSocketConfigurer {
@Autowired
private ApplicationContext context;
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
MyEndpoint endpoint = context.getBean(MyEndpoint.class);
registry.addHandler(endpoint, "/signaling");
}
}
Run Code Online (Sandbox Code Playgroud)
当连接建立时:
@Component
public class MyEndpoint implements WebSocketHandler {
private WebSocketSession wsSession;
@Override
public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception {
this.wsSession = webSocketSession;
// need to get the HTTP SESSION HERE
log.info("Opening: " + webSocketSession.getId());
}
}
Run Code Online (Sandbox Code Playgroud)
现在这是我如何使用 'javax.websocket-api' 执行此操作的示例:
配置:
@ServerEndpoint(value = "/signaling", //
decoders = MessageDecoder.class, // …Run Code Online (Sandbox Code Playgroud)