Hi,
I m new to jsp and currently i m trying to fix this problem.

In my project, we have an enhancement where we are trying to access a changepassword.jsp 1) directly through URL 2)Invoking this jsp after loginhandler.jsp.

1) is for existing users. 2) is for new users.

We have seperate error codes for new and existing users.

The 2) option is working fine. Here a new user first logs in (into the loginhandler.jsp). His errorcode is recorded using setAttribute(). Then, he is shown the changepassword.jsp and here, getAttribute(errorcode) is done and then, the new user is allowed to change the password.

However, in 1) option, we are still using the same changepassword.jsp. As a result of this, when the code encouters getAttribute(errorcode), the logic fails since this jsp is directly accessed from URL and it doesn't understand from where it has to get the attribute.

The piece of code in loginhandler.jsp is tring resul=loginRes+" ";

session.setAttribute("errorcode",resul);
------------------------------------------------------------------------------------------------------
The piece of code in changepassword.jsp is :

String ercode=(String)session.getAttribute("errorcode");

String errcode=ercode.trim();

int erCode = Integer.valueOf(errcode).intValue();

if(erCode==3016){

...........
}


Can someone help me as to how i can manage to keep the code in changepassword.jsp and handle both the kinds of users.

Recommended Answers

All 3 Replies

Uhm.... if (errcode != null) before the trim?

shouldn't the session persist even if you're redirecting to a new page? if not, would request.set/getParameter() work?

The thing is, from the way I read your post, the session will not contain any value under the key "errorcode". Therefore getAttribute("errorcode") will return null. Therefore ercode.trim() will result in a NullPointerException, therefore you need to add if (ercode != null).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.