Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem setting sessions in JSP? from IE/mozilla 1

Status
Not open for further replies.

FreshmenProgrammer

Programmer
Jan 16, 2006
42
CA
I just want to say thanks in advance for answering this post.

The following code will set session variables from a JSP in mozilla but I get all nulls for the variables in IE.

Does anyone know why that happens. Thank you.

I think scriplets work but I was told to stay away from them in views. Thank you

Code:
<c:set var="app" scope="session" value="${param.app}"/>
<c:set var="callingURL" scope="session" value="${header.referer}"/>
<c:set var="callingIP" scope="session" value="${pageContext.request.remoteAddr}"/>
<c:set var="sessionId" scope="session" value="${pageContext.request.requestedSessionId}"/>
 
Hi,

I am sorry, I dont understand the question.

For the first time if you accessing the page then all of the attributes except remoteAddr would be null.
Hit F5 (Refresh)
Will see both remoteAddr and requestedSessionId
Clck on the List
Will display all values


Below is the code, tested in both IE and FireFox works same

Code:
<%@ taglib uri="[URL unfurl="true"]http://java.sun.com/jstl/core"[/URL] prefix="c"%>
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
  </head>
  <body>
  <c:set var="app" scope="session" value="${param.app}"/>
  <c:set var="callingURL" scope="session" value="${header.referer}"/>
  <c:set var="callingIP" scope="session" value="${pageContext.request.remoteAddr}"/>
  <c:set var="sessionScope" scope="session" value="${pageContext.request.requestedSessionId}"/>
  
    App:<c:out value='${sessionScope.app}' /><br>
    URL:<c:out value='${sessionScope.callingURL}' /><br>
    IP:<c:out value='${sessionScope.callingIP}' /><br>
    Session:<c:out value='${sessionScope.sessionScope}' /><br>
    
    <br>
    <a href="<c:out value='${pageContext.request.requestURI}?app=hello'/>">Click Here</a>
  </body>
</html>

Cheers
Venu
 
Venu,

Thank you for answering. Is there anyway to get all those fields set from the very first visit. What a need is a hidden variable (eg.app) and the callingURL, along with remoteAddr and session all stored in the first visit. Thank you!
 
I forgot something .. what is happening is a 3rd party app is calling a jsp page that I made and I need to set the calling URL and a hidden variable from the 3rd party app and authenticate it to make sure the URL matches the id number. So the jsp page its calling needs to set those as sessions so when the jsp page submits to the controller the controller will have info to authenticate. Is the the best way to do it. Thanks
 
Hi,

It is better to store the information into an object and store that object into the session. Before storing it into session verify if the user is valid or not.

Well, if we take the above post then you have all the values except for requestedSessionId uses pageContext.session.id

Code:
<%@ taglib uri="[URL unfurl="true"]http://java.sun.com/jstl/core"[/URL] prefix="c"%>
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
  </head>
  <body>
  <c:set var="app" scope="session" value="${param.app}"/>
  <c:set var="callingURL" scope="session" value="${header.referer}"/>
  <c:set var="callingIP" scope="session" value="${pageContext.request.remoteAddr}"/>
  <c:set var="sessionScopeId" scope="session" value="${pageContext.session.id}"/>
  
    App:<c:out value='${sessionScope.app}' /><br>
    URL:<c:out value='${sessionScope.callingURL}' /><br>
    IP:<c:out value='${sessionScope.callingIP}' /><br>
    Session:<c:out value='${sessionScope.sessionScopeId}' /><br>
    
    <br>
    <a href="<c:out value='${pageContext.request.requestURI}?app=hello'/>">Click Here</a>
  </body>
</html>

Cheers
Venu
 
Venu,

Sorry to bother you again? I really appreciate this help. Here is what my app is doing. Its a central auth app. So someone's 3rd party app will call my jsp page puts in there user name and password then hits submit. The controller will take the username and Id authenticate it. then it should take the refer URL and the hidden app number being passed and authenticate that together but in IE i get null for the referer URL. In mozilla I get the referer URL.

For example if you write this code:
Code:
<%
String callingURL = (String)request.getHeader("referer");
System.out.println("*** from the JSP page: "+callingURL);
%>

From mozilla the you will get the referer value to print out but in IE I get null. Is there anyway to get the referer URL the first time someone access's the page. Thank you!

S.
 
Hi,

I am not sure why, but it is what might be happening. If you are using javascript:document.location.href to invoke the jsp then IE will not send "referer" URL it will be null were as FireFox (Mozilla)send the "referer" URL.

Try this test page both in IE and FF, In the page there are 2 links to the same page one uses regular JavaScript submit will use javascript:document.location to call the same page in IE you will see the referer as null if you click JavaScript submit and will see the app value as new, but in FF it will show the referer.

Work around, donot use document.location

Code:
<%@ taglib uri="[URL unfurl="true"]http://java.sun.com/jstl/core"[/URL] prefix="c"%>
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
  </head>
  <body>
  <c:set var="app" scope="session" value="${param.app}"/>
  <c:set var="callingURL" scope="session" value="${header.referer}"/>
  <c:set var="callingIP" scope="session" value="${pageContext.request.remoteAddr}"/>
  <c:set var="sessionScopeId" scope="session" value="${pageContext.session.id}"/>
  
    App:<c:out value='${sessionScope.app}' /><br>
    URL:<c:out value='${sessionScope.callingURL}' /><br>
    IP:<c:out value='${sessionScope.callingIP}' /><br>
    Session:<c:out value='${sessionScope.sessionScopeId}' /><br>
    
    <br>
    <a href="<c:out value='${pageContext.request.requestURI}?app=hello'/>">Click Here</a>
    <br>
    <a href="javascript:document.location.href='<c:out value='${pageContext.request.requestURI}?app=new'/>'">JavaScript submit</a>
  </body>
</html>

Cheers
Venu
 
Venu,

I see what you mean with the whole javascript thing but I do need javascript to pop up the window. So just say at there is this link:
Code:
<a href="#" onClick="javascript:window.open('[URL unfurl="true"]http://123.123.220.220/aaa/login.jsp?app_id=99[/URL]
&app_name=whatever','Login','height=170,width=310,left='+(screen.width-310)/2+',
top='+(screen.height-170)/2+',resizable=off');">Login</a>

(**These are just made up URL's not the real ones**)
I need app_id =99 in this case and the url to get saved in the session right away so when u log in at and submit to the controller its not blank. Will there be anyway around that while using javascript because the log in box will pop up and as soon as you log in it will disappear. If i don't use javascript I don't know how else to do this. Thank you so much and sorry about all the questions I'm new to web apps well new to programming professionally just got out of school. Thank you so much!!

S.
 
Got it. Thank you so much Venu!! I just didn't use the javascript like you said just have to figure out how to resize the window without java script now. Thanks
 
Hi,

The other way of doing it some thing like passing the href with the URL as a parameter then you don't have to worry about different browser behavior. And in the JSP page you get the parameter href.

Code:
<a href="#" onClick="javascript:window.open('[URL unfurl="true"]http://123.123.220.220/aaa/login.jsp?app_id=99[/URL]
&app_name=whatever[COLOR=red]&href=' + escape( location.href)[/color],'Login','height=170,width=310,left='+(screen.width-310)/2+',
top='+(screen.height-170)/2+',resizable=off');">Login</a>

in the jsp page
Code:
<c:set var="callingURL" scope="session" value="${param.href}"/>

Hope this will help you.

Cheers
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top