jsp-tags

JSP tag file that either outputs its body or returns it in a variable

做~自己de王妃 提交于 2019-12-22 03:49:17
问题 I have a custom tag in a ".tag" file that computes and outputs a value. Because I cannot post the code here, let's assume a simple example. Content of file mytag.tag: <@tag dynamic-attributes="dynamicParameters"> <%@attribute name="key" required="true"%> <%-- this works fine, in spite of dynamic-attributes --%> <jsp:doBody var="bodyContent/"> <%-- ... here is some code to compute the value of variable "output" --%> ${output} The caller can easily call it like this: <prefix:mytag key="foo"

How conditionally show the content of a div rather than another div in a JSP page?

我们两清 提交于 2019-12-21 21:42:27
问题 I am very new in JSP development and I have the following doubt. If into a JSP page I have 2 div like this: <div id="succes"> <p>SUCCESS</p> </div> <div id="failure"> <p>FAILURE</p> </div> and I have to show only one of these div according to the value of a status variable putted into the Http Session that can have only 2 value: OK and KO . Can I do something like this: <% if(request.getSession(false).getAttribute("status")=="OK"> { %> <div id="succes"> <p>SUCCESS</p> </div> <% } %> <% else {

Using java.time.LocalDate with JSTL <fmt:formatDate> action

折月煮酒 提交于 2019-12-21 13:03:26
问题 I haven't been able to figure out how to display a java.time.LocalDate value in a JSP. In my JSP, I have this: <fmt:formatDate value="${std.datum}" type="date" pattern="dd.MM.yyyy" var="stdDatum" /> The std.datum is of type java.time.LocalDate. When rendering the JSP I get this exception: javax.el.ELException: Cannot convert 2015-02-14 of type class java.time.LocalDate to class java.util.Date I'm assuming it's the conversion? So is it possible to format an instance of LocalDate class with

Equivalent to the deprecated <sec:authorize> ifNotGranted attribute

跟風遠走 提交于 2019-12-21 09:10:52
问题 I would like to prevent an image having a link if a user does NOT have a certain role. e.g. <sec:authorize ifNotGranted="ROLE_ACCOUNTS" ><img src="someimage.jpg"/></sec:authorize> <sec:authorize ifAllGranted="ROLE_ACCOUNTS" ><a href="somelink.htm"><img src="someimage.jpg"/></a></sec:authorize> However ifNotGranted and ifAllGranted are now deprecated in favour of the access expression. I can see that ifAllGranted can be replicated with: <sec:authorize access="hasRole('ROLE_ACCOUNTS')"><a href=

JSP Tag Files in subdirectories, using a single taglib prefix. Is that possible?

萝らか妹 提交于 2019-12-21 07:39:03
问题 I currently have my .tag files declared with: <%@taglib prefix="t" tagdir="/WEB-INF/tags" %> Example of the path of a tag file : /WEB-INF/tags/test.tag And I use them like so : <t:test oneAttributeKey="oneAttributeValue"> some content... </t:test> My problem : I don't want to put all my tag files in one single folder, "/WEB-INF/tags". I would prefere to have them in different subdirectories : /WEB-INF/tags/users/ /WEB-INF/tags/widgetsA/ /WEB-INF/tags/widgetsB/ (...) Is this possible, without

JSP Tag Files in subdirectories, using a single taglib prefix. Is that possible?

别说谁变了你拦得住时间么 提交于 2019-12-21 07:38:04
问题 I currently have my .tag files declared with: <%@taglib prefix="t" tagdir="/WEB-INF/tags" %> Example of the path of a tag file : /WEB-INF/tags/test.tag And I use them like so : <t:test oneAttributeKey="oneAttributeValue"> some content... </t:test> My problem : I don't want to put all my tag files in one single folder, "/WEB-INF/tags". I would prefere to have them in different subdirectories : /WEB-INF/tags/users/ /WEB-INF/tags/widgetsA/ /WEB-INF/tags/widgetsB/ (...) Is this possible, without

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

Difference between jsp expression tags <% and <%=

扶醉桌前 提交于 2019-12-20 11:07:02
问题 I more or less know the difference between <%! and <%, but I can't seem to find the difference between <%= and <%. I'm trying to avoid a null value error by introducing some logic into my expression that currently uses <%= ... %>. I get an error unless I replace the tags with <%...%>. However after my build I get a jsp error instead of the servlet error. I can't really paste my original code in here but the code inside <%= ... %> essentially retrieves a nested array object (more like array

JSP tag lifecycle

强颜欢笑 提交于 2019-12-19 05:22:08
问题 I just introduced a bug into my code because I seem to have misunderstood the jsp tag lifecycle. The tag worked like this before the bug: I pass the tag some collection as an attribute, and it displays it as a table. The collection was passed into the JSP from the controller. After the bug: I removed the attribute which set the collection. Instead, in the tag I check if the collection is null, and then grab it by name from the request (using a naming convention). The thing that I didn't

How to access request in JspTags?

冷暖自知 提交于 2019-12-18 03:09:22
问题 I want to call request.getContextPath() inside a JSP tag which extends SimpleTagSupport , is there any way to do it? 回答1: First get the PageContext by the inherited SimpleTagSupport#getJspContext() and then get the HttpServletRequest by PageContext#getRequest(). PageContext pageContext = (PageContext) getJspContext(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); 来源: https://stackoverflow.com/questions/2098796/how-to-access-request-in-jsptags