[英]How to set JSP variable in tag to read with <%= viewEditPromotionURL>?
I was thinking such variable can only be set by Java code: 我以为这样的变量只能由Java代码设置:
<%
String viewEditPromotionURL="http://promotion.info";
%>
but I found that it can also be set in custom tag: 但我发现它也可以在自定义标签中设置:
<portlet:actionURL name="editPromotion" var="editPromotionURL" />
How tag can set variable visible by <%=...>
? 标签如何设置<%=...>
可见的变量?
Can me myself do this? 我自己可以这样做吗? For example: 例如:
<%
String variableName = "myvariable";
String variableValue = "myvalue";
// secret part to store myvalue into myvariable
%>
<p>Variable = <%= myvariable%></p>
Is this possible? 这可能吗? What to write in the secret part? 在秘密部分写些什么?
If you look at the output from Jasper (the JSP Compiler), the <%= myvariable %>
tag is converted to: 如果查看Jasper(JSP编译器)的输出,则<%= myvariable %>
标记将转换为:
javax.servlet.jsp.JspWriter out = pageContext.getOut();
out.print(myvariable);
This means myvariable
must be defined somewhere public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
can see it. 这意味着myvariable
必须在public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
可以看到的地方定义。 Your only options are either inside the JSP page like your first code snipit, or at the class level using <%! %>
您唯一的选择是像第一个代码一样在JSP页面内,或者在类级别使用<%! %>
<%! %>
. <%! %>
。 In the <portlet:>
example you are using a taglib to add variables which you can learn more about here . 在<portlet:>
示例中,您正在使用taglib添加变量,您可以在此处了解更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.