• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

session probluem

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
aaaaaa
Asked:
aaaaaa
  • 9
  • 9
1 Solution
 
bloodredsunCommented:
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
 
aaaaaaAuthor Commented:
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
 
bloodredsunCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
aaaaaaAuthor Commented:
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
 
bloodredsunCommented:
>> 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
 
bloodredsunCommented:
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
 
aaaaaaAuthor Commented:
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
 
aaaaaaAuthor Commented:
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
 
bloodredsunCommented:
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
 
aaaaaaAuthor Commented:
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
 
aaaaaaAuthor Commented:
my mmm.jsp aaa=bbb

org.apache.jasper.runtime.jspfactoryimpl internalgetpagecontext

sereve: exception initializing page context
java.lang.stackoverflowerror
0
 
bloodredsunCommented:
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
 
aaaaaaAuthor Commented:
i open with outlook
0
 
bloodredsunCommented:
>>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
 
aaaaaaAuthor Commented:
i open with outlook
0
 
bloodredsunCommented:
Does it work okay when you use a browser like Internet Explorer or Firedfox?
0
 
aaaaaaAuthor Commented:
oh thanks, this work
<%@ page session="true" %>

very thankyou, but can u explain why?
0
 
bloodredsunCommented:
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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now