[英]How to set JSP variable in tag to read with <%= viewEditPromotionURL>?
我以為這樣的變量只能由Java代碼設置:
<%
String viewEditPromotionURL="http://promotion.info";
%>
但我發現它也可以在自定義標簽中設置:
<portlet:actionURL name="editPromotion" var="editPromotionURL" />
標簽如何設置<%=...>
可見的變量?
我自己可以這樣做嗎? 例如:
<%
String variableName = "myvariable";
String variableValue = "myvalue";
// secret part to store myvalue into myvariable
%>
<p>Variable = <%= myvariable%></p>
這可能嗎? 在秘密部分寫些什么?
如果查看Jasper(JSP編譯器)的輸出,則<%= myvariable %>
標記將轉換為:
javax.servlet.jsp.JspWriter out = pageContext.getOut();
out.print(myvariable);
這意味着myvariable
必須在public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
可以看到的地方定義。 您唯一的選擇是像第一個代碼一樣在JSP頁面內,或者在類級別使用<%! %>
<%! %>
。 在<portlet:>
示例中,您正在使用taglib添加變量,您可以在此處了解更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.