简体   繁体   中英

Calling Javascript function inside JSP scriplet

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.

我没有足够的重复点来评论,但看起来你的js函数调用应该在脚本标签中。

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>

 <%

 }

%>

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.

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