[英]JSP- Cannot call a java variable from a different JSP page?
I have two JSP pages. 我有两个JSP页面。 One of them is call
validate.jsp
and the code is as below: 其中之一是调用
validate.jsp
,代码如下:
String username = request.getParameter("username");
String password = request.getParameter("password");
String referrerURL = request.getParameter("referrerURL");
if(userFacade.validate(username, password) == false){
throw new Exception(userFacade.getMsg());
}
// Extract the Auser object of the user and stores it in the HttpSession object
Auser auser = userFacade.get(username, true);
if (auser == null) {
throw new Exception("Invalid user.");
}
String usertype = auser.getAusertype();
I have another JSP called email.jsp
and I want to call the variable in validate.jsp
我还有一个名为
email.jsp
JSP,我想在validate.jsp
调用该变量
<%@include file = "../../../login/validate.jsp" %>
Auser auser = userFacade.get(username, true);
My directory for include file is definitely correct but however it couldn't resolve username
in this JSP. 我的包含文件目录绝对正确,但是无法解析此JSP中的
username
。
Can anyone point out any mistake I made? 谁能指出我犯的任何错误?
EDIT: 编辑:
Found out that username
is inside a try catch block and if i placed it outside, I can call the variable. 发现
username
位于try catch块内,如果我将其放在外部,则可以调用该变量。 Is there a way to call it inside a try catch from another jsp? 有没有办法在另一个jsp的try catch中调用它?
You mentioned that removing the try/catch block "fixed" the issue. 您提到删除try / catch块可以“解决”该问题。 If that is the case then just define the variable outside the block, otherwise the scope is limited to only inside the block.
如果是这种情况,则只需在块外部定义变量,否则范围仅限于块内部。
String username = "";
try {
username = request.getParameter("username");
...
} catch (...)
Would something like this make sense? 这样的事情有意义吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.