1. <%@ page contentType="text/html; charset=GBK" language="java"%>
2. <%@taglib prefix="s" uri="/struts-tags"%>
3. <html>
4. <head>
5. <title>s:if標簽測試</title>
6. </head>
7. <body>
8. <s:set name="age" value="29"/>
9. <s:if test="${age > 60}">
10. 老年人
11. </s:if>
12. <s:elseif test="${age > 35}">
13. 中年人
14. </s:elseif>
15. <s:elseif test="${age > 15}" id="wawa">
16. 青年人
17. </s:elseif>
18. <s:else>
19. 少年
20. </s:else>
21. </body>
22. </html>
比如登陸模塊
<s:textfield label="用戶名" name="user.username"/>
<s:password label="密碼" name="user.password"/>
這樣寫的話,他會默認換行,可以不換行嗎?
只要你將它的這個theme屬性設成simple那么它就不會用Struts2的格式了,每個STRUTS1的標簽都有這樣的一個性!!!!
@Override
public String execute() throws Exception {
topic = topicService.getTopic(topicId);
reply.setTopic(topic);
replyService.replyTopic(reply);
return this.SUCCESS;
}
<action name="replyTopic"
class="cn.bbs.nhpop.web.action.ReplyTopic">
<result name="success" type="chain">
<param name="actionName">listTopicsDetails</param>
</result>
</action>
<s:form action="replyTopic">
<s:hidden name="topicId" value="%{topicId}"></s:hidden>
<%-- <s:param name="topicId" value="%{topicId}"></s:param>--%>


</s:form>
這是我的reply.jsp,開始我使用<s:param></s:param>傳topicId,想當然的認為可以與<s:form></s:form>合用傳參,導致replyTopic Action無法獲取到topicId的值
@Override
public String execute() throws Exception {
topic = topicService.getTopic(topicId);
reply.setTopic(topic);
replyService.replyTopic(reply);
return this.SUCCESS;
}
topic為null拋異常。(<s:url action=""><s:param></s:param></s:url>是可以這樣傳參的,但與<s:form></s:form>不行)
后來用<s:hidden></s:hidden>代替解決。另外
<s:hidden name="topicId" value="topicId"></s:hidden>
value="%{topicId}"切不可省去%{}否則Action中的topicId的值為字符串為"topicId"而不是我希望的int值1,%{topicId}相當于
<s:property value="topicId"/>
你可以使用%{}或嵌套<s:property>標簽。struts2標簽的屬性可以接受一個字符串的值的時候請大家尤其注意,必須使用%{} 或<s:property>才會是你想要的值。比如:
<s:hidden name="topicId" value="%{topicId}"></s:hidden>


<s:url id="toReply" action="toReply">
<s:param name="topicId" value="topicId"></s:param>
</s:url>

<tr>
<td height="18" colspan="2">
<s:a href="%{toReply}">回復 </s:a>
</td>
</tr>
<s:select name="page" list="page" listKey="key" listValue="value" value="page"></s:select>
@SuppressWarnings("unchecked")
public List<HashMap> getPage(){
List<HashMap> numPage = new ArrayList<HashMap>();
for(int i=0;i<10;i++){
HashMap m=new HashMap();
m.put("key", i);
m.put("value", i+1);
numPage.add(m);
}
return numPage;
}
2. <%@taglib prefix="s" uri="/struts-tags"%>
3. <html>
4. <head>
5. <title>s:if標簽測試</title>
6. </head>
7. <body>
8. <s:set name="age" value="29"/>
9. <s:if test="${age > 60}">
10. 老年人
11. </s:if>
12. <s:elseif test="${age > 35}">
13. 中年人
14. </s:elseif>
15. <s:elseif test="${age > 15}" id="wawa">
16. 青年人
17. </s:elseif>
18. <s:else>
19. 少年
20. </s:else>
21. </body>
22. </html>
比如登陸模塊
<s:textfield label="用戶名" name="user.username"/>
<s:password label="密碼" name="user.password"/>
這樣寫的話,他會默認換行,可以不換行嗎?
只要你將它的這個theme屬性設成simple那么它就不會用Struts2的格式了,每個STRUTS1的標簽都有這樣的一個性!!!!
問題:No result defined for action cn.bbs.nhpop.web.action.ReplyTopic Action and result input 錯誤
意思是說沒定義input的跳轉結果.







原因:我的cn.bbs.nhpop.web.action.ReplyTopic Action execute方法返回SUCCESS,但是實際運行中出現了錯誤(拋了異常),Action并沒有返回SUCCESS而是返回INPUT(Action出現錯誤時默認的返回值),而我的struts.xml配置文件中并沒有定義與INPUT對應的Result






解決方法:你可以添加一個與INPUT對應的Result或者解決Action方法實際運行中的異常。
我的Action到底拋了個什么異常呢?













后來用<s:hidden></s:hidden>代替解決。另外















<s:select name="page" list="page" listKey="key" listValue="value" value="page"></s:select>
@SuppressWarnings("unchecked")
public List<HashMap> getPage(){
List<HashMap> numPage = new ArrayList<HashMap>();
for(int i=0;i<10;i++){
HashMap m=new HashMap();
m.put("key", i);
m.put("value", i+1);
numPage.add(m);
}
return numPage;
}