httpsession

How to inject dependencies into HttpSessionListener, using Spring?

只谈情不闲聊 提交于 2019-12-28 02:06:14
问题 How to inject dependencies into HttpSessionListener, using Spring and without calls, like context.getBean("foo-bar") ? 回答1: Since the Servlet 3.0 ServletContext has an "addListener" method, instead of adding your listener in your web.xml file you could add through code like so: @Component public class MyHttpSessionListener implements javax.servlet.http.HttpSessionListener, ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws

Accessing HttpSession in PreProcessInterceptor

血红的双手。 提交于 2019-12-24 15:35:33
问题 Is it possible to access/create the HttpSession in the preProcess method of a PreProcessInterceptor ? (RestEasy 2.3.4) 回答1: You can access the HttpSession by injecting the HttpServletRequest using the @Context annotation and then getting the session from the request like so: @Context private HttpServletRequest servletRequest; @Override public ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException { HttpSession session = servletRequest

implementing HttpSessionListener

老子叫甜甜 提交于 2019-12-24 03:27:56
问题 I am facing a similar problem and have learnt that my listener class will be instantiated when the web.xml is read. I have few functions in the listener class that are used by the main servlet's doPost(which interacts with the database(mysql) to read/write data regarding the users.)along with the methods of HttpSessionListener. So what prevents the container from loading the listener class. I am getting the 404 error. snippet: public class EntryServlet extends HttpServlet{ public void doPost

java httpsession is valid?

两盒软妹~` 提交于 2019-12-23 12:19:18
问题 i'm using java servlet in tomcat. i save in a hash table the username and the httpsession with the attribute usrname i would like to know if there is a way to know if the httpsession is valid. i tried: try{ String user = httpSession.getAttribute("username") return "is valid"; }catch(IllegalStateException e){ return "is not valid"; } tnks for the answer, but how can i do if i don't wont that a "logged" user connect from more the one place? if i controll only if i create a new session i can't

Cannot resolve Struts2 NotSerializableException even after update to 2.3.12

纵饮孤独 提交于 2019-12-23 10:06:09
问题 I currently doing a work with struts2 and this error suddenly appears. Some cache of my objects is not working. I use JBoss 5 and struts2 : struts2-core-2.3.4.1.jar xwork-core-2.3.4.1.jar The stack trace is here : http://pastebin.com/QpPV01wX this is some snippet : java.io.NotSerializableException: com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164) at java.io.ObjectOutputStream.writeObject

Beans serialization in JSP

匆匆过客 提交于 2019-12-22 16:44:32
问题 Why some times tutorials make beans implement Serializable object and others do not? I know that object should be serialized when I want to send it through a network, so does that prove that each bean used in sessions should implements Serializable objects and beans defined in JSP pages should not since they are not transferred using HTTP requeset 回答1: I know that object should be serialized when I want to send it through a network, so does that prove that each bean used in sessions should

is @Autowired HttpSession thread safe in springmvc?

这一生的挚爱 提交于 2019-12-22 12:44:09
问题 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? 回答1: 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

is @Autowired HttpSession thread safe in springmvc?

给你一囗甜甜゛ 提交于 2019-12-22 12:44:00
问题 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? 回答1: 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

How can I get session from a common class in Spring Boot?

雨燕双飞 提交于 2019-12-22 10:28:20
问题 I want to get session from a common class. Using @Autowired didn't work. public class TMessageHandlerFactory implements MessageHandlerFactory { @Autowired private HttpSession session; @Override public void data(InputStream data) { int userId = (int)session.getAtrribute("key"); //session null .... //do sth } } The constructor also didn't work @Component public class SMTPRunner implements ApplicationRunner { @Autowired private UserService userService; // userService can access @Autowired

JSF request-scoped managed bean http-session causes in-instantiation

你离开我真会死。 提交于 2019-12-21 23:45:58
问题 I'm using a SessionFilter servlet for validating users and then giving access of the system to them. My restricted files are in a folder named "com.shadibandhan.Restricted". Session filter is working fine. here's the relevant code of the sessionfilter servlet @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse)