Session in JSP
Hi all,
I used session in my JSP pages. Now when user click Logoff link the page goes to a JSP page and there i invoked
session.invalidate();to end the session.
On that page there is a link to login again.
If the user use that and then login with a different ID and store some info in database it still shows previous users ID meaning that session is still getting old value although i invalidated it.
Can anyone please help me.
Hi CodeYoda,
Thanks for reply. I tried your code but still it doesn't work.
Now let me explain the situation, When i turned the machine this morning and started tomcat and run my application with a different ID, and i did some updates in database and it still shows the ID that i used when i created the session couple of weeks back.
Now i think this is a serious matter because it remembrs that ID only.
Now let me clear the concept again. my jsp pages are not linked by data transfer but they have links of all pages on the menu in every page so when they login and in the second page i stored the login name in session after that i used it in a page which has no connection with any other pages. Now what i did is i made the page available for session and then i used the login name.
Now is that mean that the login name is stored in that pageforever and since it doesn't send anything to logoff page and when we kill the session inlogoff page it is only killed in logoff page. That's my assumption. Can you please confirm me.
Thanks
Similar Messages
-
Hi all,
i built a web application now i want to use session in JSP pages to remember some variable such as password and entered date because i need them in later pages and i also don't want to send them via HTML hidden field. I actually don't know how to use session. Can anyone please just tell me how to create a session and store a variable and also how to retrieve the data from the session.
Another thing is guys can anyone tell me please that say i am user and i selected some items from a HTML select list and i submitted that and logged off the system now when i login later again i want to see those choices selected by default , i know it might have been done by sessions can anyone please tell me.
THANKS VERY MUCHThis is the way u can set and retrieve values from session
<% session.setAttribute("key","value"); %>
<% String user=(String)session.getAttribute("user");
%>
regards
Shanu -
How to Handle user Session in JSP
Help me,
How to handle user session in JSP.......Prakash_Pune wrote:
tell me some Debugging tech. so i can overcome from my problem.....Do you use an IDE? Any IDE ships with a decent debugger where in you can just execute the code step by step, explore the current variable values and check what exactly is happening. For example Eclipse or IntelliJ. If you don´t use an IDE, then just place some System.out.println() or Logger.debug() statements at strategic locations printing the variables of relevance so that you can track in logs what exactly is happening.
or tell any other way to find is my page is thread safe or not...Just write correct code and narrow the scope of the variables as much as possible. If you for example assigned the user object to a static variable or as a servlet´s instance variable, then exactly the same user object would be used everywhere in the application. That kind of logical things. -
How to clear session in JSP?
I searched yahoo, and found that it seemed not easy to force invalid the session using jsp, compared to php just three lines:
session_start();
session_unset();
session_destroy();
How to acheive this using JSP? Must I follow these (quite complex) steps like this one?
http://sdc.sun.co.jp/javasystem/technote/cluster/jsp.html
Any simplier method?
Thx.Not at all, it's very simple.
<%
session.removeAttribute("attributeName");
%>
This HttpSession API document shows all methods that can be called on the session object : http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSession.html -
What is the use of session in jsp
hai,
what is the use of session in jsp. i cant understand from books. give some practical approach
thanksgive some practical approachYou sound like a supervisor ordering for a cup of coffee.
I DONT TAKE ORDERS !!
IMAO
Which book did you refer ? Did you google ? -
Want to get ApEx session in JSP
Hi Pals,
From my ApEx application, I am calling a JSP by providing a direct URL.
THe JSP does some specific function here.
If the user get the JSP url by right click and view source, they can very well use this outside my ApEx application.
I want to apply security like, the JSP url only works inside my ApEx application.
My thought, if I can share ApEx session with JSP session I can impose the security check in JSP level.
Any idea would be appreciable.Hi,
Im using below method to call jsp page and passing UserName, application id and Session as
<iframe src="http://apex.oracle.com/pls/otn/...javaapplication.jsp?userId=&USER.&appId=&APP_ID.&sessId=&SESSION."></iframe>
Vailidation is done against the table "wwv_flow_sessions$" of schema : flows_030100 ,whether those values are exist in table.
But if user is already logged into apex application, he can run the jsp independantly taking the url from "view source".
Im also looking for more solid validation
Regards,
Benz -
Making a session in jsp.
I want ti make a session in jsp.
suppose if any budy can login through login page which is
www.harshworld.info/login.jsp
they will just direct open that page
www.harshworld.info/wallpage.jsp
then this page will not open . & user will see The login page it self.
So after making session in jsp what can i do ?
& how to Do can one help me.
PL Thanks for Giving time to meTHk dear
there's always a session...
if(session.getAttribute("username") == null) {
response.sendRedirect("login.jsp");
return;
and put the attribute in the session on successful
login..
Or look up other security modes. -
Handling Session in jsp and bean scope
i have problems with handling session in jsp
I want to check on all jsp pages
first thing is session is null
i want to him to be redirected to first page
and he should not be able to go ahead
I tried
if(session ==null)
response.sendRedirect("Login.jsp");
but this does not seem to work
It is very crtical problem can any one answer
this asap
Also i wanted to know that
I have bean which in turn calls static methods of another class which holds all DomainTable(database tables which do not change frequently)
Information .
This is bean is being implemented by me
in seession scope in a jsp
Do u guys think it would be goo idea to change
scop of this bean as Application in jsp
if so what would be advantages for same
I would appericate if i could a quick reply on both
question
as i am time crunch
arshYou will always get some value of session and your code wont work. At the end of your Login.jsp, you should create a sesssion and store attributes. Check for these attributes in session, rather than checking session==null.
-
Hi,
I am having trouble in maintaining session in jsp frames. -
Here is sample code
parent.jsp
<HTML>
<HEAD>
<LINK rel=stylesheet type="text/css" href="defaults.css">
<TITLE>abc</TITLE>
<%
String checkAmount = "100.00";
session.setAttribute("checkAmount", checkAmount);
System.out.println("checkAmount in ppmain"+session.getAttribute("checkAmount"));
%>
<FRAMESET rows="235,*" frameborder="no" >
<FRAME NAME="pptop" SRC="top.jsp" frameborder=0 scrolling=no noresize >
<FRAME NAME="ppbottom" SRC="bottom.jsp" frameborder=0 scrolling=no marginwidth=0 marginheight=0 noresize>
</FRAMESET>
</HTML>
top.jsp -
<HTML>
<HEAD>
<LINK rel=stylesheet type="text/css" href="defaults.css">
<TITLE>top</TITLE>
<%
System.out.println("session in top "+session);
System.out.println("checkAmount in top "+session.getAttribute("checkAmount"));
%>
</HTML>
It is not able to retain session in the top.jsp ( in SOP for session I get different session ID in parent.jsp and top.jsp
This Works well in local but when gets deployed to WAS6 server troubles starts.
Any help is appreciated.
ThanksWhen you create URLs, you might want to try using JSTL to rewrite them:
<FRAME NAME="pptop"
SRC="<c:url value='top.jsp'/>"
frameborder=0
scrolling=no
noresize >
<FRAME NAME="ppbottom"
SRC="<c:url value='bottom.jsp'/>"
frameborder=0
scrolling=no
marginwidth=0
marginheight=0
noresize>Or you can use:
SRC='<%= response.encodeURL("top.jsp") %>' -
Hi,
I am working on a JSP based website, where I am facing problem with sessions. The user is asked to login by providing her id and password. If found correct, a bean is created and populated with all her details and placed in session scope. I plan to use the information stored in the bean on other related pages until she logs out.
<jsp:useBean id="validUser" scope="session" class="UserBean" >
<c:set target="${validUser}" property="userId" value="${fn:trim(dbValues.UserId)}" />
<c:set target="${validUser}" property="userName" value="${fn:trim(dbValues.UserName)}" />
</jsp:useBean>
<c:redirect url="userHome.jsp" /> The user is presented her homepage - 'userHome.jsp', where she can find various links, like 'Update Profile', 'Pay Registration Fees', 'Book Room' etc. The information stored in the bean is available on 'userHome.jsp'page.
<A HREF='userHome.jsp'>Home</A>
<A HREF='editPersonal.jsp'>Update Profile</A>
<A HREF='registrationFee.jsp'>Pay Registration Fees</A>
<A HREF='bookRoom.jsp'>Book Room</A>
<A HREF='logout.jsp'>Logout</A> The problems are:
1. Whenever user clicks on any of the above mentioned links and moves to any page, the bean comes out as null.
<%-- Verify that the user is logged in --%>
<c:if test="${validUser == null}">
<jsp:forward page="loginForm.jsp">
<jsp:param name="origURL" value="${pageContext.request.requestURL}" />
<jsp:param name="errorMsg" value="You must be logged in to access this site." />
</jsp:forward>
</c:if> 2. The URL shows an additional jsessionid, which my client doesn't want to see.
3. On every click on any link, the value of this jsessionid changes.
What I presume, when I am clicking on different links, my session changes, and so I am seeing a different jsessionid. And since session is changing, therefore the bean is not available in a different session.
All this works fine with localhost, problem comes into picture, when I upload my pages to the server.
Puzzled, can anyone help, where am I going wrong? Let me add here, I am new to JSP and hence don't have much resources with me.There are several ways sessions can be exchanged between the browser and the server in a j2ee web application.
1. The default is through cookies. However when the client does not accept cookies, the server appends the session id to the url.
2. Some servers also facilitate session information exchange using session id in the url even if the client does accept cookies. This is usually ahieved through a setting in some server configuration file.
You will have to find out why the server in your application is appending the session id to the url.
Whatever be the case, the server should be able to look up the session from the incoming request (be it from the session id in the url or a session cookie).
When session information is exchanged through the JSESSIONID in the url, you should ensure that each and every url that goes to the server has this input parameter. To do that all links and form post urls in your servlet/jsp should be treated with a call to encodeURL().
For example, in a jsp
<a href = "<%=response.encodeURL("/nextJsp.jsp")%>">Click here </a>
or
<form action = "<%=response.encodeURL("/nextJsp.jsp")%>">
</form>etc.
ram. -
How to create a new session in JSP file
Usually a child IE window uses same session with parent window. Dose someone know how to create a new session when creating a new IE window by clicking a URL in parent window? The web page is writen by jsp file.
I am not sure of your question. Are you wanting to have 2 Session objects (one for the parent window and another for the child)?
A session is usually created once per client and is stored on the server the session id is carried around in a cookie or a URL rewrite so that everytime the user submits a page you will be able to store/access information.
// this will create a new session object if one doesn't already exist.
HttpServletRequest.getSession( true );
Hope this helps -
Session Timout JSP Page Forward
Hi All,
I am currently working on a JSP site and want to add a JSP page forward that takes place when the user's session times out after a period of inactivity.
I have created a servlet that implements HttpSessionBindingListener and has methods in place for valueBound and valueUnboud. The methods are getting called as they should, however because there isn't an HttpResponse object I cannot do a response.forward....
So my question: Is the HttpSessionBindingListener the correct interface to be implementing to accomplish my goal? If so, how do I forward the user to the login page? If not, what should I use and how do I forward the user to the login page?
Thanks for your time and help.
AaronvalueUnbound method? Arent you using a Model
View Controller type architecture? The servlet
is mainly used to to handle logic and navigate
to the appropriate view(your java server pages).
The code I supplied should be placed in the service
method of your servlet.. then it can handle the
request and determine where to go from there. Your
servlet should have three methods, the doPost, the
doGet, and the service method. The doPost and Get
should pass the request and response objects on to
the service method. Any other logic should be handled
in other classes that you create. The service method
basically decides what the next page should be.
Hope this helps.. -
Error in accessing pageContext or current session for JSP/servlet in frames
I am creating a web application on iPlanet application server (ver 6.0 SP4) and display a page
consists of frames in web browser (IE6). The framset and the content of each frames are
JSPs or servlets. There where no problem to display each content frames individually at all.
However, when the overall page (the frame set and the 3 frames) is displayed, the following
problem occurs.
Only the outermost frameset and just one or two of the frame contents displayed successfully
in browser. Others have either 1 of the following errors:
1. When accessing pageContext object in _jspService routine when displaying the JSP page, Null
Pointer Exception occurs:
java.lang.NullPointerException
Exception Stack Trace:
java.lang.NullPointerException
at jsp.APPS.intl.acct_type_option._jspService(acct_type_option.java:653)
2. When calling the req.getSession method in doGet() method for servlets, the following
exception occurs:
Exception in doGet(): This session has already been invalidated
The occurance of error is random among all the frames. With the frame on top or left size
having the most chance to be displayed successfully.
It seems that the Application server cannot entertain 3 or 4 requests simultaneously (which
happens when displayed a page consists of frames), having some of them throw an exception.
Are they any tuning or setting for iPlanet server to overcome this problem?I'll give you the same advice as I have been given regarding the use of frames.
Don't use them at all. Use scrollable DIV's instead.
The use of frames is such that you would have different JSP's who cannot collaborate together since each is in his own frame and does not know about the others.
In case I'm mistaken, I'd like to hear about it, but the combination of JSP's and frames is an unhappy one. -
How to putput a property of an object in session? (jsp/struts)
Guys,
I have an object (myGroup) that consist of 2 properties: groupName and groupTitle. The object is in a session called group_session.
On my jsp page, I would like to output the property groupName on the text field associated with the groupName:
<html:text property="name"
value=???????????????
size="45"
maxlength="60" />
<html:errors property="name" />Q: how can I output the value of the groupName in the value section?
thanksHi
you can try something like this....
<input type="text" name="any" property="<bean:write
name="myGroup" property="groupName "
scope="session"/> " >
This snippet is closer to JSP coding rather than struts. Leverage the capabilities of struts by setting the values in ActionServlet instead.
<html:text property="name" size="45" maxlength="60" /> -Rohit
By the way why did you add this tag
<html:errors property="name" /> ??
Message was edited by:
RohitKumar -
how to set & get sessions parameters in jsp / servlets.
thanxi know the methods setAttribute() & getAttribute().
what i wanted to know is like request.setAttribute & request.getAttribute() does session.setAttribute() & session.getAttribute() is corect or not?????????
if i do session.setAttribute("Test","Test1") in a JSP/servlet then can i do session.getAttribute("Test') in another jsp/servlet
Maybe you are looking for
-
Hi Experts, I have two questions related to POWL, please help me: 1. Where can I set the columns as hierarchy colunms that use can choose them for hierarchy display? And how can I set the default hierarchy colunms? 2. It seems the system cannot remem
-
Start of week problem in Apple Mail
Just noticed a weird problem after setting up a couple of smart-mailboxes. I set up two with the settings for 'Mail delivered this week' and 'Mail delivered last week'. However today, Sunday, I noticed that Mail has decided to filter the results in t
-
Hi all, I have created one internal claim assigned it to the WBS element and give cost to cost estimation space assigned PO to it which is assigned to the WBS element. But when i am seeing the reports of PS cost or hierarchy reports then th
-
Printing Different Documents giving problem
Dear Friends. I need one help, i.e., When I am Printing Voucher(Paper size 8.5*12 Inch) Check (Paper size 7*4 Inch) Prenum Note( Dina 4) (all are on same Printer). (SAP 0S is NT,and FrontEnd PC OS XP) Problem is,If I change printer properties(Pag
-
Fn:SUM in Xquery getting error
Hi All Gm, I am using fn:sum in xquery.I am getting multiple data as request. Using fn;Sum if I add more 7 digits ,it is converting to hexadecimal.but I don't want to convert hexadecimal value. ex: fn:sum(9999999,0,100)= 9896E3.(sum of 8 digits conv