1. <%@ page contentType="text/html; charset=GBK" language="java"%>
2. <%@taglib prefix="s" uri="/struts-tags"%>
3. <html>
4. <head>
5. <title>s:if標(biāo)簽測(cè)試</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"/>
這樣寫的話,他會(huì)默認(rèn)換行,可以不換行嗎?
只要你將它的這個(gè)theme屬性設(shè)成simple那么它就不會(huì)用Struts2的格式了,每個(gè)STRUTS1的標(biāo)簽都有這樣的一個(gè)性!!!!
@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,開(kāi)始我使用<s:param></s:param>傳topicId,想當(dāng)然的認(rèn)為可以與<s:form></s:form>合用傳參,導(dǎo)致replyTopic Action無(wú)法獲取到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>不行)
后來(lái)用<s:hidden></s:hidden>代替解決。另外
<s:hidden name="topicId" value="topicId"></s:hidden>
value="%{topicId}"切不可省去%{}否則Action中的topicId的值為字符串為"topicId"而不是我希望的int值1,%{topicId}相當(dāng)于
<s:property value="topicId"/>
你可以使用%{}或嵌套<s:property>標(biāo)簽。struts2標(biāo)簽的屬性可以接受一個(gè)字符串的值的時(shí)候請(qǐng)大家尤其注意,必須使用%{} 或<s:property>才會(huì)是你想要的值。比如:
<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}">回復(fù) </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標(biāo)簽測(cè)試</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"/>
這樣寫的話,他會(huì)默認(rèn)換行,可以不換行嗎?
只要你將它的這個(gè)theme屬性設(shè)成simple那么它就不會(huì)用Struts2的格式了,每個(gè)STRUTS1的標(biāo)簽都有這樣的一個(gè)性!!!!
問(wèn)題:No result defined for action cn.bbs.nhpop.web.action.ReplyTopic Action and result input 錯(cuò)誤
意思是說(shuō)沒(méi)定義input的跳轉(zhuǎn)結(jié)果.







原因:我的cn.bbs.nhpop.web.action.ReplyTopic Action execute方法返回SUCCESS,但是實(shí)際運(yùn)行中出現(xiàn)了錯(cuò)誤(拋了異常),Action并沒(méi)有返回SUCCESS而是返回INPUT(Action出現(xiàn)錯(cuò)誤時(shí)默認(rèn)的返回值),而我的struts.xml配置文件中并沒(méi)有定義與INPUT對(duì)應(yīng)的Result






解決方法:你可以添加一個(gè)與INPUT對(duì)應(yīng)的Result或者解決Action方法實(shí)際運(yùn)行中的異常。
我的Action到底拋了個(gè)什么異常呢?













后來(lái)用<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;
}