struts.xml文件<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />
    
    <package name="example" namespace="/" extends="struts-default"> <action name="HelloWorld" class="example.HelloWorld">

<result name="success">/HelloWorld.jsp</result>

</action>
</package>
</struts>
import com.opensymphony.xwork2.ActionSupport;public class HelloWorld extends ActionSupport { public String execute() throws Exception {
setMessage("你好!Struts 2!");
return SUCCESS;
}

private String message;

public String getMessage() {
   return message;
}
public void setMessage(String message) {
   this.message = message;
}
}
JSP页面<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title></title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
在浏览器上访问http://localhost:8080/webtest/HelloWorld显示
${message}
无法得到message 值但是可以用<s:property value="message"/>这个标签得到请问各位高人那里错了用到是STRTUS最小的包, xwork-2.1.2.jar,struts2-core-2.1.6.jar,spring-test-2.5.6.jar,ognl-2.6.11.jar,junit-3.8.1.jar,freeer-2.3.13.jar,commons-logging-1.1.jar,commons-io-1.3.2.jar,commons-fileupload-1.2.1.jar

解决方案 »

  1.   

    你这个显示用的freeer?需要把struts默认解析改为freeer的。
    在配置文件中,    
    <package name="struts-default" abstract="true">
    </package>
    有个freeer返回类型,改为默认就行
      <result-type name="freeer" class="org.apache.struts2.views.freeer.FreeerResult" default="true"/>或者只改
    struts.xml中,你写的配置文件,返回类型为freeer即可。
      

  2.   

    还是不太明白,result type=freeer 后面对应的应该是.fl文件啊好象
    麻烦高人告诉我这个文件怎么改吧<struts>
        <constant name="struts.enable.DynamicMethodInvocation" value="false" />
        <constant name="struts.devMode" value="false" />
        
        <package name="example" namespace="/" extends="struts-default">    <action name="HelloWorld" class="example.HelloWorld">
        
        <result name="success">/HelloWorld.jsp</result>
           
        </action>
    </package>
    </struts>
      

  3.   

    “$”有两个主要的用途   1. 用于在国际化资源文件中,引用OGNL表达式
       2. 在Struts 2配置文件中,引用OGNL表达式,如
          <action name="AddPhoto" class="addPhoto">
                      <interceptor-ref name="fileUploadStack" />            
                      <result type="redirect">ListPhotos.action?albumId=${albumId}</result>//通过action的getAlbumId()取值
            </action>
      

  4.   

    现在我遇到的是在JSP文件中无法取得message的值
    <%@ page contentType="text/html; charset=GBK" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <html>
    <head>
    <title><s:property value="message"/></title>  //这里可以得到值
    </head>
    <body>
    <h2>${message}</h2>//这里得不到值,原样显示为${message}
    </body>
    </html>我是照着书上的例子来做的,怎么也显示不了${message}
    这种方式在JSP上不能用吗, 它是FREEMARKER的标签吗,是不是JSTL的
      

  5.   

    已经搞定, 
    WEB.XML的版本问题需要在JSP头部加上<%@ page isELIgnored="false" %>