I don't have enough rep points to comment, but it looks like your js function call should be in script tags.
Calling Javascript function inside JSP scriplet
-
16-07-2023 - |
سؤال
I have a javascript function that needs to be called under a condition.
The condition is given below
<%if(request.getAttribute("isValidUser").equals("false"))
{%>
Redirect();
<%}%>
Redirect()
is the function name that I have declared and defined in the section.
When I execute the page I am getting the following error.
org.apache.jasper.JasperException: An exception occurred
processing JSP page /HomePage.jsp at line 136
HomePage.jsp:
133: <p><input type="password" name="password" id="password" placeholder="Password"/></p>
134: <span id="nullPassword" class="error"></span>
135: </div><span style="color:red;">
136: <%if(request.getAttribute("isValidUser").equals("false"))
137: {%>
138: Redirect();
139: <%}%>
Please help me out.
Thank you.
المحلول
نصائح أخرى
getAttribute returns an object and you may need to typecast.
On another note:
Javascript and JSP are two different things. JSPs will undergo a compilation process just like your Java files. Only if the compilation is successful, the JSP can be "reached".
Javascript on the other hand will execute on the browser.
Put the javascript function call within tags
<%
if(request.getAttribute("isValidUser").equals("false"))
{
%>
<script>Redirect();</script>
<%
}
%>
لا تنتمي إلى StackOverflow