简体   繁体   English

如何在jsp中保持变量不变?

[英]How to keep variable unchange in jsp?

I have the following code snippet in jsp: 我在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. 重定向后,此处的变量Key被更改。 How can I keep this variable unchanged after redirection? 重定向后如何保持此变量不变?

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. 在会话中使用密钥是更好的选择。

You can't keep values in variables on every page redirection because WEB is stateless. 由于WEB是无状态的,因此不能在每个页面重定向中都将值保留在变量中。 so you need to use sessions 所以你需要使用会话

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM