Why Am I Getting A Null value? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Why Am I Getting A Null value?

stricksstricks Posts: 33Member
[b][red]This message was edited by stricks at 2005-6-24 5:31:35[/red][/b][hr]
This is reading a file in a class named GetConfig

[code]
...
String mystr;
while ((mystr = in.readLine()) != null) {
if(mystr.equals("")){
surveyFile = in.readLine();
System.out.println(surveyFile);
}
...
[/code]

When that prints out to the console I get the path name of the file.

When I go to use that from another class...

[code]
...
GetConfig config = new GetConfig();
...
// I store that string into this string

String setup_file = config.surveyFile;
...

// Then I send it to the session. And call a jsp page

session.setAttribute("error", setup_file);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/The_Test/error.jsp");
dispatcher.forward(request, response);
[/code]

JSP page:
[code]
<%
String error = "what";
error = (String) session.getAttribute("error");

out.print(error);
%>
[/code]

null gets print out to the screen instead of the orignal string. Why?

thank you.



Comments

  • moomoo Posts: 147Member
    >> ...
    >> [code]
    >> // Then I send it to the session. And call a jsp page
    >>
    >> session.setAttribute("error", setup_file);
    >> RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/The_Test/error.jsp");
    >> dispatcher.forward(request, response);
    >> [/code]
    >>
    >>JSP page:
    >>[code]
    >><%
    >> String error = "what";
    >> error = (String) session.getAttribute("error");
    >>
    >> out.print(error);
    >>%>
    >>[/code]
    >>
    >> null gets print out to the screen instead of the orignal string.
    >> Why?
    >>
    >> thank you.

    Hi,
    it seems the session objects are not the same, is it possible that the JSP's session object isn't the *same* object where you set the attribute ?

    mo
  • stricksstricks Posts: 33Member
    Yeah, that's what I figured out :-P

    Thanks though!

    Strick
Sign In or Register to comment.