I am making a web application based on Spring 3 and Apache Wicket. When the user of the application click on element, after the timeout of the session, the application crash because the HTML file doesn't find the Java component. How can I prevent this?
By default Wicket will create a new instance of the page if the old one is gone for any reason: https://github.com/apache/wicket/blob/38bee6e932e63fa033c2139cdfb2f82eba55fadc/wicket-core/src/main/java/org/apache/wicket/settings/PageSettings.java#L46
Maybe this setting is false for you ?!
Behind you spring/wicket app you have a Java Servlet Web application. Set the timeout=0 and sessions won't expire.
Include this block in the web.xml. You can also do it programatically.
<web-app ...>
<session-config>
<session-timeout>0</session-timeout>
</session-config>
</web-app>
I believe you are looking for ExpiredErrorPage Configure below in yourApplication init() method
Whenever session expired it will redirect to loginpage . It will not show like crashed .so that you can login again and do your stuff.
getApplicationSettings().setPageExpiredErrorPage(LoginPage.class);
Related
I am using Wildfly, Spring MVC in my project.
And after redirecting to another page of my project - to my browser address line appears some session info like in this image:
p.s. When i were using Tomcat - there was no such problems.
Is there an optimal way to stop auto-adding session information in the address bar?
Thanks.
Update:
In the normal situation, when i were redirecting in my past projects(for example) from page "index" to page "login" i saw something like this: "myapp.com/login"
But now i saw:"myapp.com/login;jsessionid=nGTE5tfW3hUZZOP1yQTF4Mrh3PRbNu8UyY8UBkmx.coderunit".
I didn't made some special options to my app server to cancel this session info additions. Maybe there are some special tool for it.
I solved this problem.
There is some spectial option for web.xml.
This is the default behavior of a servlet container. If the client doesn’t include a cookie in the first request, the container cannot tell whether the client supports cookies or not. Therefore the container embeds the session id in the URL.
You can disable this in your web.xml using the session-config element:
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
It helped me. Good luck.
I would like to test my webapplication (JSF 2.2) which has a custom Esxception Handler Factory.
Now i would like to know if everything works as expected when a javax.faces.application.ViewExpiredException is thrown. Is there any way, I can decrease the time to wait for getting this exception?
Throwing it programmatically is not an option, as I would like to have a nearly 100% productive test scenario.
As far as I'm concerned, it should be enough to force a Session expiration while you keep the JSF view state in the server side:
Setting STATE_SAVING_METHOD to client has however an additional functional advantage: it prevents ViewExpiredExceptions when the session has expired or when the client opens too many views.
So, being the javax.faces.STATE_SAVING_METHOD defaulted to server, you only need to specify the timeout you want for the Http Session:
<session-config>
<session-timeout>2</session-timeout>
</session-config>
As an alternative, you could choose to set your own limit of views. That depends on the concrete JSF implementation, Mojarra defaults to 16 and MyFaces to 20. For the first one, you could use com.sun.faces.numberOfLogicalViews to decrease the amount of views accepted simultaneously per client. As an example, setting it to 3 should fire the exception when you've got four tabs opened in the same browser (same Http Session).
See also:
What is STATE_SAVING_METHOD parameter in JSF 2.0
Session TimeOut in web.xml
How can I set the view timeout?
In Google Chrome you can use the Developer Tools to delete the session cookie.
Web.xml
you should have something like:
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
Where the timeout is in minutes, so set to 1
I'm doing my first Java EE web application and I'm struggling with sessions.
in my web.xml file I put the following settings:
<session-config>
<session-timeout>30</session-timeout>
</session-config>
But if I close my browser which is not configured to delete cookies on close,
after reopen the session is over.
How can I have a "persistent" session ?
check if a cookie named Jsessionid is getting created during your first request. And close your browser open it again and check if that cookie is still there and value is same.
I think it will not be, and that is the reason your session expires.
When a cookie's expiration is set to "session", it will get deleted by the browser when the user closes the browser. This has nothinng to do with the web.xml session-timeout setting, which will force-close the Java EE session server-side if there are no requests by the user in the designated timespan.
Spring has "remember me" functionality:
http://static.springsource.org/spring-security/site/docs/3.0.x/reference/remember-me.html
I need to change the session time for my web Application.
The web application is created using Struts 2.0 and is deployed on Tomcat Web Server.
I tried it by changing the timeout in web.xml of server like below.
<session-config>
<session-timeout>1</session-timeout>
</session-config>
And also i tried it by puting above code in web.xml of Web Application.
But both of above solutions did not work.
Still, Web Applicaiton session is maintained for 30 minutes. Please suggest how can i change the session timout value.
Thanks
Jyoti
It should work. Put it in webapps/yourapp/WEB-INF/web.xml. Remove it from the server's web.xml. And make sure everything is freshly redeployed.
Also make sure you are not interacting with the session (including ajax) for that amount of time.
I have written a facelets web application using tomcat as a application server. My program has a foobar.xhtml and the URL to it is:
http://localhost:8080/Myapplication/foobar.faces
Can I change something in my application so that a link to:
http://localhost:8080/Myapplication/
..will actually render my application on http://localhost:8080/Myapplication/foobar.faces ?
Alternatively, could the http://localhost:8080/Myapplication/ be redirected to http://localhost:8080/Myapplication/foobar.faces ?
You would normally use the <welcome-file> entry in the web.xml for this. But unfortunately this doesn't work as expected on at least Tomcat when using fictive URL's which are to be passed through a servlet like a FacesServlet. Tomcat will scan for the physical file on the disk matching the exact name before forwarding. If it isn't present, then you will just face a default 404 error page.
Using /foobar.xhtml as <welcome-file> is also not going to work since that page requires to be parsed by the FacesServlet to get all the JSF stuff to work.
One of the ways to fix this is to place another real /foobar.faces file there next to the real /foobar.xhtml file. It doesn't need to be filled with code, it can be left empty. Just the presence of the physical file is enough for Tomcat to open the desired page as welcome page.
web.xml has a
<welcome-file-list>
<welcome-file>foobar.faces</welcome-file>
</welcome-file-list>
element where you can define the page to be opened.