scriptlet

Accessing a jstl variable inside a scriptlet

感情迁移 提交于 2019-11-27 01:15:42
问题 The following code causes an error: <c:set var="test" value="test1"/> <% String resp = "abc"; resp = resp + ${test}; //in this line I got an Exception. out.println(resp); %> Don't I use the expression language "${test}" in the scriptlet.why? 回答1: JSTL variables are actually attributes, and by default are scoped at the page context level. As a result, if you need to access a JSTL variable value in a scriptlet, you can do so by calling the getAttribute() method on the appropriately scoped

Creating Array using JSTL or EL

一世执手 提交于 2019-11-26 22:53:53
问题 I'm working on a web application using Java and its frameworks(Spring 3.1.1). And I'm trying to avoid using scriptlets as much as possible, however I can't find a way other than this to define an array: <% String[] alphabet = {"A", "B", "C", ... , "Z"}; pageContext.setAttribute("alphabet", alphabet); %> After setting pageContext attribute, I can use it with ${alphabet} . But I want to know, is it possible to use plain JSTL/EL to create an array? UPDATE: I'm using this array to create links.

How to evaluate a scriptlet variable in EL?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 17:55:51
I was wondering if there was anyway of using JSP in <c:if> statement. E.g. <c:if test="${ param.variable1 == 'Add' <% JSP variable clause %>}"> So I want my JSP variable to checked against as well. Any suggestions? I have tried ignorantly just sticking in the clause, obviously it did not work. Thanks BalusC So you want to evaluate a scriptlet variable in EL? Store it as a request attribute. <% String var = "some"; request.setAttribute("var", var); %> <c:if test="${param.variable1 == 'Add' && var == 'some'}"> However, this makes no sense. You should avoid scriptlets altogether and use JSTL/EL

I can pass a variable from a JSP scriptlet to JSTL but not from JSTL to a JSP scriptlet without an error

本小妞迷上赌 提交于 2019-11-26 10:18:02
问题 The following code causes an error: <c:set var=\"test\" value=\"test1\"/> <% String resp = \"abc\"; resp = resp + test; pageContext.setAttribute(\"resp\", resp); %> <c:out value=\"${resp}\"/> The error says \"error a line 4: unknown symbol \'test\'\". How do I pass test from the JSTL code to the JSP scriptlet? 回答1: Scripts are raw java embedded in the page code, and if you declare variables in your scripts, then they become local variables embedded in the page. In contrast, JSTL works

How to evaluate a scriptlet variable in EL?

感情迁移 提交于 2019-11-26 05:38:40
问题 I was wondering if there was anyway of using JSP in <c:if> statement. E.g. <c:if test=\"${ param.variable1 == \'Add\' <% JSP variable clause %>}\"> So I want my JSP variable to checked against as well. Any suggestions? I have tried ignorantly just sticking in the clause, obviously it did not work. Thanks 回答1: So you want to evaluate a scriptlet variable in EL? Store it as a request attribute. <% String var = "some"; request.setAttribute("var", var); %> <c:if test="${param.variable1 == 'Add' &

How to avoid Java code in JSP files?

霸气de小男生 提交于 2019-11-26 03:11:14
问题 I\'m new to Java EE and I know that something like the following three lines <%= x+1 %> <%= request.getParameter(\"name\") %> <%! counter++; %> is an old school way of coding and in JSP version 2 there exists a method to avoid Java code in JSP files. Can someone please tell me the alternative JSP 2 lines, and what this technique is called? 回答1: The use of scriptlets (those <% %> things) in JSP is indeed highly discouraged since the birth of taglibs (like JSTL) and EL (Expression Language,

How to avoid using scriptlets in my JSP page?

你。 提交于 2019-11-26 01:45:26
问题 I\'ve been told that the use of scriptlets (<%= ... %>) in my JSP pages isn\'t such a great idea. Can someone with a bit more java/jsp experience please give me some pointers as to how to change this code so its more \'best practice\', whatever that may be? This JSP is actually my sitemesh main decorator page. Basically my web design has a tab strip and a submenu, and i wish to somehow highlight the current tab and show the correct submenu by looking at the current request URI. <%@ taglib uri

How to avoid using scriptlets in my JSP page?

让人想犯罪 __ 提交于 2019-11-25 19:17:26
I've been told that the use of scriptlets (<%= ... %>) in my JSP pages isn't such a great idea. Can someone with a bit more java/jsp experience please give me some pointers as to how to change this code so its more 'best practice', whatever that may be? This JSP is actually my sitemesh main decorator page. Basically my web design has a tab strip and a submenu, and i wish to somehow highlight the current tab and show the correct submenu by looking at the current request URI. <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <html> <head> <title>My Events -