I have two JSP pages. One of them is call validate.jsp
and the code is as below:
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
<%@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.
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. Is there a way to call it inside a try catch from another jsp?
You mentioned that removing the try/catch block "fixed" the issue. 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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.