httpsession

How to get HttpSession from sessionId in grails application

无人久伴 提交于 2019-12-10 12:14:21
问题 I have grails application, using sessionRegistry I can get sessionId. Now, how can I get HttpSession from that sessionId. 回答1: If you want the HttpSession then how about this: import org.springframework.beans.BeansException import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContextAware import org.springframework.stereotype.Component import org.springframework.web.context.WebApplicationContext import javax.servlet.http.HttpSession import javax

Spring MVC - difference between HttpSession.setAttribute and model.addObject

自闭症网瘾萝莉.ら 提交于 2019-12-09 06:35:48
问题 I am trying to learn Spring MVC recently. It seems that i did not understand well the functionalities of @ModelAttribute annotation and HttpSession. @SessionAttributes({"shoppingCart", "count"}) public class ItemController { @ModelAttribute("shoppingCart") public List<Item> createShoppingCart() { return new ArrayList<Item>(); } @ModelAttribute("count") public Integer createCount() { return 0; } @RequestMapping(value="/addToCart/{itemId}", method=RequestMethod.GET) public ModelAndView

How to store session in Spring MVC

我怕爱的太早我们不能终老 提交于 2019-12-09 04:03:42
问题 What's the best way of storing session related data of a user (like, for example a log of recent actions a user has done) in a Spring MVC (2.5) web application ? Using the classic javax.servlet.http.HttpSession or by specifying scope="session" in controller beans, and storing the data in a session object ? 回答1: Session-scoped beans (using scope="session" ) is the cleanest approach. This removes the need to interact with the session yourself. If you want to autowire a session-scoped bean in to

Spring MVC when autowired HttpSession will be created?

大兔子大兔子 提交于 2019-12-08 12:13:32
问题 Issues in using AutoWired HttpSession: LoginController calls LoginService passing HttpServletRequest as parameter. I've autowired HttpSession like this in few other annotated classes (but NOT in LoginService): @Autowired private HttpSession httpSession; In LoginService class, if I try to get session by calling request.getSession(false) I receive null in some instances. If I try to get session by calling request.getSession(true) I am ending up with two HttpSession objects (one here and another

java.lang.IllegalStateException thrown while setSessionToken in TokenHelper

不问归期 提交于 2019-12-08 06:24:41
问题 I have a Java application running on Linux OS with Jetty server. Struts action which changes the date and time of Linux System and after it renders another page. An action is performed successfully but while rendering the page it will throw java.lang.IllegalStateException. I have used "s:token" in that JSP page for preventing double submissions of form. Error Trace is as below ERROR TokenHelper Error creating HttpSession due response is committed to client. You can use the

Spring MVC - Session differences

南笙酒味 提交于 2019-12-07 16:54:02
问题 Are there any differences between getting session through HttpServletRequest.getSession() and HttpSession injected in controller's method? 回答1: Basically there is no diffrerence between the session object injected into a Spring MVC controller: @RequestMapping(value = "/somepath", method = RequestMethod.POST) @ResponseBody public JsonResponse someMethod (HttpSession session) { // play with session attributes } And the session object retrieved from the HttpServletRequest : @RequestMapping(value

mvc controller test with session attribute

偶尔善良 提交于 2019-12-07 12:21:14
问题 I'm trying to test a method with this signature: @Autowired HttpSession http_Session; @RequestMapping(method=RequestMethod.GET, value="/search/findByName") public @ResponseBody List<Map> search(@RequestParam(value="name", required=true) String name){ Integer user_id = http_Session.getAttribute("userinfo"); } userinfo is a class which contains informations about the user and set in session scope when the user logged in.but when I try the test : @RunWith(SpringJUnit4ClassRunner.class)

Spring MVC: How autowiring of HttpSession works?

孤街醉人 提交于 2019-12-06 15:20:23
问题 I would like to know how autowiring of HttpSession works. If we declare like below: @Autowired private HttpSession httpSession; When exactly in the Spring workflow, httpSession variable declared above will be initialized with request.getSession(true) ? 回答1: I don't understand why you want to autowire HttpSession but here is how autowiring works. To Autowire a class you need to specify it as a bean either by using annotations (@Controller, @Service, @Repository, @Component) or by declaring

is @Autowired HttpSession thread safe in springmvc?

人盡茶涼 提交于 2019-12-06 11:21:42
I'm using HttpSession object in Spring MVC with @Autowired : public abstract class UserController { @Autowired public HttpSession session; @RequestMapping(value = { "" }, method = { RequestMethod.GET }) public ModelAndView index(){ User user=(User)session.getAttribute("loginUser"); } } is the session thread-safe? iwein What you get wired from Spring is just the HttpSession. There are no special thread safety guarantees. Implementations using HttpSession are not necessarily thread safe. See also this question: Is HttpSession thread safe, are set/get Attribute thread safe operations? You could

How to set the values in session?

混江龙づ霸主 提交于 2019-12-06 09:10:59
问题 If I'm getting empty session I need to setup some values to play the action class. So, here is the method public SearchFilters getFilters() { return (SearchFilters) getSession().get("Filters"); } I would like to check the session, if it's null , then I need to set the some values over here. public SearchFilters getFilters() { if(getSession().get("Filters").equals(null)){ ---- //How to set the values and return ? } return (SearchFilters) getSession().get("Filters"); } 回答1: public SearchFilters