176142998

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  116 Posts :: 0 Stories :: 45 Comments :: 0 Trackbacks
   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的标签都有这样的一个性!!!!



问题:No result defined for action cn.bbs.nhpop.web.action.ReplyTopic Action and result input 错误

意思是说没定义input的跳转结果.

    @Override
    
public String execute() throws Exception {
        topic 
= topicService.getTopic(topicId);
        reply.setTopic(topic);
        replyService.replyTopic(reply);
        
return this.SUCCESS;
    }

原因:我的cn.bbs.nhpop.web.action.ReplyTopic Action execute方法返回SUCCESS,但是实际运行中出现了错误(抛了异常),Action并没有返回SUCCESS而是返回INPUT(Action出现错误时默认的返回值),而我的struts.xml配置文件中并没有定义与INPUT对应的Result

        <action name="replyTopic"
            class
="cn.bbs.nhpop.web.action.ReplyTopic">
            
<result name="success" type="chain">
                
<param name="actionName">listTopicsDetails</param>
            
</result>
        
</action>

 

解决方法:你可以添加一个与INPUT对应的Result或者解决Action方法实际运行中的异常。

我的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">
                    
&nbsp;
                    
<s:a href="%{toReply}">回复 </s:a> &nbsp;
                
</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;
  
 }
posted on 2008-08-01 14:23 飞飞 阅读(2785) 评论(2)  编辑  收藏

Feedback

# re: s:if标签测试 2012-05-10 17:30 大幅度
我认为而  回复  更多评论
  

# 3 2012-05-10 17:31 请问恶
阿斯顿  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: