scriptlet

JSP include page doesn't work

允我心安 提交于 2019-12-24 14:50:10
问题 I have a JSP file, member.jsp which is as follows : <%@ page import="java.util.*" %> <jsp:include page="/html_functions.jsp" /> <% String heading = "Header" %> <%= formStart("a_form") %> <%= printPageHeader(heading) %> <%= startMyLi() %> <%= endLi() %> <%= formEnd() %> and my html_functions.jsp is as follows : <%! public String formStart(String name) { String structure = "<div id=\"content\"><form name=\"" + name + "\" method=\"post\"><ul>"; return structure; }//formStart public String

ajax on aui:select liferay

眉间皱痕 提交于 2019-12-24 03:31:00
问题 I know this is impossible to pass parameter from javascript to scriptlet code in jsp page So I want to use ajax to post my selected value to server and then get it in scriptlet code by request object I use <aui:select label="My Selection" name="ms" id="ms" onchange="<%= updateItem()%>" > <% for(String item : itemList){ %> <aui:option selected="<%= item.equals(selItem) %>" value="<%=item%>"><%=item%></aui:option> <%}%> </aui:select> <%! private Object updateItem() throws Exception{ //to do

how to get the value from javascript code to jsp scriptlet with in the same jsp page

大憨熊 提交于 2019-12-23 18:40:21
问题 below is my code (1.jsp) <html> <head> <script type="text/javascript"> function changeFunc() { var selectBox = document.getElementById("selectBox"); var selectedValue = selectBox.options[selectBox.selectedIndex].value; document.write("\n value is"+selectedValue); } </script> </head> <body> <form method="post" action="SampServlet"> <select id="selectBox" name="selurl" onchange="changeFunc();"> <option value="1">Option #1</option> <option value="2">Option #2</option> </select> </form> </body> <

JSP tags + scriptlet. How to enable scriptlet?

那年仲夏 提交于 2019-12-21 03:41:04
问题 I have a page which uses a tag template. My web.xml is very basic. I simply want to run some code in the page. And no, I'm not interested in tags or other alternative. I want to use the bad-practice scriptlet haha. So far I'm getting this "HTTP ERROR 500" error: Scripting elements ( %!, jsp:declaration, %=, jsp:expression, %, jsp:scriptlet ) are disallowed here. While my files look like: /WEB-INF/web.xml <?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001

Passing a List from Servlet to JSP

南笙酒味 提交于 2019-12-20 03:42:29
问题 When I try to set the value of a list in Servlet to a session variable and access it JSP like, doGet HttpSession session = request.getSession(true); session.setAttribute("MySessionVariable", authorizeUserList); JSP <%List lst = session.getAttribute("MySessionVariable");%> I get an error in JSP as "List cannot be resolved to a type" So how should I do this? I want to pass a list from Servlet to JSP and populate a Drop down. 回答1: Are you importing list and casting? <%@page import="java.util

invoking java scriptlet in JSP using HTML

大兔子大兔子 提交于 2019-12-19 10:53:17
问题 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 回答1: You can use Ajax to submit form to servlet and

Use EL ${XY} directly in scriptlet <% XY %>

独自空忆成欢 提交于 2019-12-17 10:03:33
问题 In my project I've to asign a variable every time the JSP is being opened. I tried it with scriptlets <% %> in JSP and EL ${} which gives the variable back. But it seems not working. <% String korrekteAntwort=${frage.korrekteAntwort};%> <%session.setAttribute("korrekteAntwort", korrekteAntwort);%> There is an error after korrekteAntwort=${} , Isn't it possible to asign directly an variable from EL in a scriptlet? 回答1: You're mixing scriptlets and EL and expecting that they run "in sync". That

How do I pass JavaScript values to Scriptlet in JSP?

柔情痞子 提交于 2019-12-17 02:51:29
问题 Can anyone tell me how to pass JavaScript values to Scriptlet in JSP? 回答1: Your javascript values are client-side, your scriptlet is running server-side. So if you want to use your javascript variables in a scriptlet, you will need to submit them. To achieve this, either store them in input fields and submit a form, or perform an ajax request. I suggest you look into JQuery for this. 回答2: I can provide two ways, a.jsp , <html> <script language="javascript" type="text/javascript"> function

Disadvantages of using scriptlet? [duplicate]

人盡茶涼 提交于 2019-12-13 16:12:54
问题 This question already has answers here : How to avoid Java code in JSP files? (30 answers) Closed 5 years ago . I want to know the whole thing about using scriplet. Why is it not recommended when coding JSP(s). Everytime I ask about coding with scriptlet, they pointing me not to use it and use JSTL instead. 回答1: There are several articles on the web comparing scrptlets and JSTL (I guess you've googled for some first) and most of them will tell you the same JSTL are easier to test, maintain

Difference between <%= foo %> and ${ foo }

北战南征 提交于 2019-12-12 16:26:08
问题 Coding in JSP for the first time, I need to render a variable's value to HTML. It looks like there are various ways to do this; what is the difference between these (given that I have a variable named foo )? <%= foo %> and ${ foo } 回答1: This, using an old fashioned output scriptlet which is discouraged since a decade, <%= foo %> does basically the same as the following in a regular scriptlet : <% out.println(foo); %> which in turn does basically the same as the following in a normal Java