scriptlet

How do i embed java code inside jsf page?

浪子不回头ぞ 提交于 2019-12-04 13:46:41
I have: A managed bean called "LoginBean". A JSF page called "login.xhtml" In this jsf page, i have a login form. Inside the managebean i have a loginCheck function. public void loginCheck(){ if(logincorrect){ //set user session }else{ //set lockout count session ++ } } What i want to do in my jsf page is that when the lock out count session == 2 (means users failed to login correctly 2 times, i need a recaptcha tag to be displayed. <td> <% if(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("numberOfLogins") == 2){ <p:captcha label="Captcha" requiredMessage="Oops,

Are methods legal inside JSP scriptlet?

谁都会走 提交于 2019-12-03 08:16:50
问题 I know its not recommended, and I should be using tag libraries etc etc. But I'd still like to know if it is legal to declare methods in a JSP scriplet: <% public String doSomething(String param) { // } String test = doSomething("test"); %> Is that legal? I am getting some weird compile errors (like a ; is expected ) that don't seem to fit. Thanks. 回答1: You need to use declaration syntax ( <%! ... %> ): <%! public String doSomething(String param) { // } %> <% String test = doSomething("test")

Scriptlet in js

蓝咒 提交于 2019-12-02 15:01:17
问题 i have a jsp page... i am adding some content to page dynamically depending upon request parameters (an array will be returned by request) based on this i have to create a drop down. i want to do this on change of another drop down.. so can be done using javascript only but i am unable to use scriptlet in js, is this really possible?? EDIT : i wanna perform some actions on the values retrieved from scriptlet as well it will be of this sort function changeMethod(){ var templateselected =

Passing a variable from Scriptlets to Javascript.

三世轮回 提交于 2019-12-02 11:32:33
问题 I have this code snippet :: <script type="text/javascript"> function gotoa(){ <%! public void a(){ String temp1; PopulateTextbox obj = new PopulateTextbox(); temp1 = obj.method(); request.setAttribute("variable", temp1); } %> var myVar = <%=request.getAttribute("variable")%> } </script> What i want to do is to get the value of variable temp1 in my JavaScript function gotoa(). In this particular code i am getting an error invalid request request.setAttribute("variable", temp1); My main aim is

Java Expression works in JSTL tags but not in Struts 2 tags of a JSP page

独自空忆成欢 提交于 2019-12-02 10:28:28
I am using "JSTL" ans "struts2" in my project.I am trying set a value in the scope using JSTL and Struts2 tag as follows, <div id="id1"></div> <div id="id2"></div> <% int b=10; %> <c:set var="test2" value="<%= b %>"/> <s:set var="test3" value=" <%=b%>" /> <script> document.getElementById("id1").innerHTML="${test2}"; //10 document.getElementById("id2").innerHTML="${test3}"; //nothing is displayed. </script> The output is 10 only. My doubt is why the expression <%= b %> works in <c:set> tag and not work in <s:set> tag? Struts tags doesn't allow scriptlects in the tag's attributes. But you can

Scriptlet in js

核能气质少年 提交于 2019-12-02 07:42:11
i have a jsp page... i am adding some content to page dynamically depending upon request parameters (an array will be returned by request) based on this i have to create a drop down. i want to do this on change of another drop down.. so can be done using javascript only but i am unable to use scriptlet in js, is this really possible?? EDIT : i wanna perform some actions on the values retrieved from scriptlet as well it will be of this sort function changeMethod(){ var templateselected = document.getElementById("templateDropDown"); var versionDropDown = document.getElementById("versionDropDown"

Making scriptlets invalid in JSPs

孤街醉人 提交于 2019-12-02 05:01:50
问题 I am trying to make scriptlets invalid by writing the below code in my Deployment descriptor but still the scriptlets are getting executed. <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <scripting-invalid>false</scripting-invalid> <el-ignored>true</el-ignored> </jsp-property-group> </jsp-config> 回答1: You need to configure it the other way round. <scripting-invalid>true</scripting-invalid> <el-ignored>false</el-ignored> When the <scripting-invalid> is set to true , then

Passing a variable from Scriptlets to Javascript.

此生再无相见时 提交于 2019-12-02 03:10:33
I have this code snippet :: <script type="text/javascript"> function gotoa(){ <%! public void a(){ String temp1; PopulateTextbox obj = new PopulateTextbox(); temp1 = obj.method(); request.setAttribute("variable", temp1); } %> var myVar = <%=request.getAttribute("variable")%> } </script> What i want to do is to get the value of variable temp1 in my JavaScript function gotoa(). In this particular code i am getting an error invalid request request.setAttribute("variable", temp1); My main aim is to call the function a() on some button click event so that my script let code runs again and fresh

Making scriptlets invalid in JSPs

[亡魂溺海] 提交于 2019-12-02 02:38:58
I am trying to make scriptlets invalid by writing the below code in my Deployment descriptor but still the scriptlets are getting executed. <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <scripting-invalid>false</scripting-invalid> <el-ignored>true</el-ignored> </jsp-property-group> </jsp-config> You need to configure it the other way round. <scripting-invalid>true</scripting-invalid> <el-ignored>false</el-ignored> When the <scripting-invalid> is set to true , then the container will throw an exception when scriptlets (those <% %> , <%= %> and <%! %> things) are still used.

invoking java scriptlet in JSP using HTML

耗尽温柔 提交于 2019-12-01 12:19:44
I am trying to find a way to invoke a piece of java code within the JSP using HTML form <form method="get" action="invokeMe()"> <input type="submit" value="click to submit" /> </form> <% private void invokeMe(){ out.println("He invoked me. I am happy!"); } %> the above code is within the JSP. I want this run the scriptlet upon submit I know the code looks very bad, but I just want to grasp the concept... and how to go about it. thanks gkiko You can use Ajax to submit form to servlet and evaluate java code, but stay on the same window. <form method="get" action="invokeMe()" id="submit"> <input