?
Solved

session probluem

Posted on 2005-04-05
18
Medium Priority
?
347 Views
Last Modified: 2012-05-05
when i use email to open my web

<form action="http://localhost/mmmm.jsp" method=post>
<input type=submit value="GO"/>
</form>

in mmmm.jsp i set:
session.setAttribute("aaa","bbb");
System.out.println("my aaa="+session.getAttribute("aaa"));
response.sendRedirect("pppp.jsp");

in pppp.jsp
System.out.println("my aaa="+session.getAttribute("aaa"));

my result is:
aaa=bbb
aaa=null

why null??
0
Comment
Question by:aaaaaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
18 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13706180
Why are you writing to the tomcat logs with System.out.println? To write to the page you should use out.print()

This:
mmmm.jsp
<%
session.setAttribute("aaa","bbb");
out.print("my mmmm.jsp aaa="+session.getAttribute("aaa"));
response.sendRedirect("pppp.jsp");
%>

pppp.jsp
-----------
<%
out.print("my aaa="+session.getAttribute("aaa"));
%>

prints
--------
my aaa=bbb

which shows it works. What's the error?
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 13706238
the error come out when my pppp.jsp more than 270 line

and this only happen when i open with email!

u know what is mean?

<form action="http://localhost/mmmm.jsp" method=post>
<input type=submit value="GO"/>
</form>
if this is in a *.html, is work fine and i will get my aaa=bbb

but when i open by email, my aaa=null
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13706243
Even if you do this

mmmm.jsp
------------------
<%
session.setAttribute("aaa","bbb");
out.print("my mmmm.jsp aaa="+session.getAttribute("aaa"));
System.out.println( "my mmmm.jsp aaa="+session.getAttribute("aaa") ) ;
response.sendRedirect("pppp.jsp");
%>

pppp.jsp
------------------
<%
out.print("in pppp.jsp my aaa="+session.getAttribute("aaa"));
System.out.println( "in pppp.jsp my aaa="+session.getAttribute("aaa") ) ;
%>


pppp.jsp outputs this in the browser
------------
in pppp.jsp my aaa=bbb


and the tomcat log output is
------------
my mmmm.jsp aaa=bbb
in pppp.jsp my aaa=bbb

Which shows that both work as they should...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:aaaaaa
ID: 13706286
same i got null.

u know what i need to do?

i try to access my web click my a email.

please the notice is 'EMAIL'.

is working fine if i click from anyjfdkljfla.html
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13706301
>> the error come out when my pppp.jsp more than 270 line
>>and this only happen when i open with email!
>>u know what is mean?

Sorry no. Could you explain a little more please? How do you "open with email"

0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13706313
I notice your form action is "http://localhost/mmmm.jsp". So you are working in the root directory and have changed the tomcat port to 80, is that correct?
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 13706364
my testing.html
****************************
<form action="http://localhost/mmmm.jsp" method=post>
<input type=submit value="GO"/>
</form>
****************************
when i click 'GO', it point to http://localhost/mmmm.jsp, then redirect to
http://localhost/pppp.jsp, then show value: my aaa=bbb


____________________________________________________________
in my email.
*****************************
<form action="http://localhost/mmmm.jsp" method=post>
<input type=submit value="GO"/>
</form>
******************************
when i click 'GO', it point to http://localhost/mmmm.jsp, then redirect to
http://localhost/pppp.jsp, then show value: my aaa=null

0
 
LVL 4

Author Comment

by:aaaaaa
ID: 13706406
in my http://localhost/pppp.jsp page
**************************************
<%
out.print("my aaa="+session.getAttribute("aaa"));
...
....
...
..
.. totally 270 line here
%>
i look my extra 269 line i s no probluem.

but dun know why if open my html it work fine, but open my email cannot
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13706409
Try this in mmmm.jsp:

<%
session.setAttribute("aaa","bbb");
out.print("my mmmm.jsp aaa="+session.getAttribute("aaa"));
System.out.println( "my mmmm.jsp aaa="+session.getAttribute("aaa") ) ;
RequestDispatcher rd = request.getRequestDispatcher("pppp.jsp");
rd.forward(request, response) ;
%>
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 13706424
summary:

1)open by html, with pppp.jsp line 270
  fine

2)open by email, with pppp.jsp line 270
   null

3)open by html, with pppp.jsp line 1
   fine

4)open by email. with pppp.jsp line 1
   fine also
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 13706475
my mmm.jsp aaa=bbb

org.apache.jasper.runtime.jspfactoryimpl internalgetpagecontext

sereve: exception initializing page context
java.lang.stackoverflowerror
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13706642
Just to be clear, when you say open with email, do you mean open with web-based email like hotmail or opened with an email client like Outlook?

The 270 line problem may be the fact that compiled JSPs cannot be larger than 64K. This is because javac does not allow a single method to be larger than 64K and JSPs can be considered to be just on large method. But that should be caught on compilation. It can be worked around by breaking the page up into smaller subsections and using jsp:include to build a single bigger page.
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 13706666
i open with outlook
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13706668
>>org.apache.jasper.runtime.jspfactoryimpl internalgetpagecontext

This happens when the server can't get the session from the request

Try adding <%@ page session="true" %> to the top of mmmm.jsp

Just to be clear, when you say open with email, do you mean open with web-based email like hotmail or opened with an email client like Outlook?

The 270 line problem may be the fact that compiled JSPs cannot be larger than 64K. This is because javac does not allow a single method to be larger than 64K and JSPs can be considered to be just on large method. But that should be caught on compilation. It can be worked around by breaking the page up into smaller subsections and using jsp:include to build a single bigger page.
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 13706691
i open with outlook
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13706706
Does it work okay when you use a browser like Internet Explorer or Firedfox?
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 13706708
oh thanks, this work
<%@ page session="true" %>

very thankyou, but can u explain why?
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 2000 total points
ID: 13706986
It must be that the HTTP request to the page was not a POST or a GET, which meant that the session was not being created. Adding <%@ page session="true" %> forces the server to generate the session object which is then available to be written to.

Glad to have helped. It was a bit of an odd problem but we got there in the end!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
The Summer 2017 Scholarship Winners have been announced!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question