user1679430
user1679430

Reputation: 3

How to keep variable unchange in jsp?

I have the following code snippet in jsp:

String Key=null;

if(request.getParameter("project")!=null) { 
        Key = request.getParameter("project").trim();
}

if (AM == null) {
        response.sendRedirect("../portal/login.jsp?from=index.jsp");
}

In here after redirection the variable Key is changed. How can I keep this variable unchanged after redirection?

Upvotes: 0

Views: 141

Answers (2)

ponraj
ponraj

Reputation: 768

You can use key in session parameters otherwise you can use like this

String Key=null;

    if(request.getParameter("project")!=null){ 
        Key=request.getParameter("project").trim();
     }

if (AM == null) {
        response.sendRedirect("../portal/login.jsp?from=index.jsp&project="+Key);
    }

Using key in session is better one.

Upvotes: 1

Netorica
Netorica

Reputation: 19327

You can't keep values in variables on every page redirection because WEB is stateless. so you need to use sessions

http://www.jsptut.com/sessions.jsp

Upvotes: 0

Related Questions