can't get attribute from session - session

I have a web application, and I want to use an object, which I save in the seesion.
When I run the web app in eclipse it's work fine, but it dosen't work on the browser.
The object which I get from the session is null.
In the servlet I have this code:
request.getSession().setAttribute("wrapper", wrapper);
and in the jsp, where I need this attribute I have the code:
WrapperMLP wrapper = ((WrapperMLP) request.getSession().getAttribute("wrapper"));
thanks in advance

Try making a new session object in servlet as:-
HttpSession session=request.getSession(true);
session.setAttribute("wrapper",wrapper);
and in jsp write your code:
WrapperMLP wrapper = ((WrapperMLP) request.getSession().getAttribute("wrapper"));

Related

how many way to access the scope variables in spring-mvc

Some one please me to find out the spring mvc examples,
Because usually, once we log in into the application we will create a session and put some objects into session . we will access later point of time , request scope as well. but spring MVC3 is difficult to understand even documentation also confusing, but every one giving example is basic examples only.
You can access these objects in a JSP/JSTL:
applicationScope
cookie
header
headerValues
initParam
pageContext
pageScope
param
paramValues
requestScope
sessionScope
As well as any request attributes that you add, including model attributes (who's default name is command).
More info here: http://www.informit.com/articles/article.aspx?p=30946&seqNum=7
If you want to access HttpRequest, HttpResponse, HttpSession, add them as arguments to a Spring Controller Handler Method . Spring will pass them in for you.

how to avoid creating new session using window.open()?

window.open(url) is creating a new session.
Is there any way to prevent window.open() from doing the same. I heard using servlet dispatcher instead of window.open(). we can avoid making new session but i have no idea how to use the dispatcher in jsp or js file. All i have right now is the url in my javascript file.

how can i get the Response Object in Spring MVC in a normal Bean

someone could tell me ,how can i get Response in a normal bean in spring, actually,
what i am gonna to do is to create a proxy to check whether a user is log in or not ,if it's not ,i would send him to my home page,if it does,then the request goes to spring mvc's Controller,i know i can get the HttpServletRequest Object with declaring the RequestContextListenerin web.xml, i want to get the Response Object, and then i could do the forward withRequestDispatcher` .is there a way to get the response object? or you have a solution to this, thanks in advance, i am waiting online ..

Spring MVC Load page automatically

I have a quick question about how to use the Spring MVC.
I just started with it and i was used to have pages that always had their data loaded calling some controller that you setted ON THE PAGE.. calling some methods on controllers to load objects at the page at load time.
Is it the same in Spring MVC? Cuz what im seeing so far is that if you want to load a page with data, you always have to use a modelandview object which is loaded by a method that you must call before... and them you return the modelandview object with its destination to the view that you want.
What im trying to know is if there is a way that the page requests some data from the controller before it gets loaded... automatically...
Dont know if im making my self clear... thanks anyway for the help!
in spring mvc, using Controllers, it is always Request->Controller(populates model and chooses view)->Response.
you could use ajax to load data from any resource (even Controllers) or jsp:useBean to explicitly call some business logic or jsp:include to include a certain fragment or a custom jsp tag.
I also face the same situation.
check the below link for getting the data from the controller before view(JSP) load.
how to load the data into index page

How session sets and unsets in JSF2.0

I want to know about setting and un-setting the session in JSF2.0. Although following some blogs and books (Core JavaServer Faces-3rd Edition), i got to know that using annotation #SessionScoped we can set any manage bean to be in session. I have a loginBean which is #ManagedBean and SessionScoped declared. On the top right corner, my web has login button.
When this session is created (i am not setting it manually, that is why i am confused) and when i gets destroyed? It must be destroyed either by time out or by clicking in logout button only.
JSF uses the Servlet API under the covers. A session scoped managed bean is in essence set as an attribute of the HttpSession. It will be created and set whenever the EL expression referencing the managed bean #{sessionBean} is evaluated for the first time. It will be "removed" from the session whenever the session expires (by either a restart of the client or a timeout in the server) or get invalidated. If you let your logout button call ExternalContext#invalidateSession(), then the session will be invalidated.
If you're familiar with the basic Servlet API, you should already understand how this all works. For an in-depth explanation of the Servlet's HttpSession works under JSF's covers, read this answer: How do servlets work? Instantiation, sessions, shared variables and multithreading.
In jsf 2.0 we can set total class ob as session like i mention
Class_name sm;
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext(); extContext.getSessionMap().put("Give name for access this property",sm);
Class_name sm = (Class_name) extContext.getSessionMap().get("Give name for access this property");

Resources