LoginAction.javapackage com.action;
import com.dto.User;
import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{

private static final long serialVersionUID = 7018507302660403636L;
private User user;

public String execute() throws Exception {
if (user.getName().trim().equalsIgnoreCase("a")&&user.getPassword().equals("b")) {
return SUCCESS;
}else {
return ERROR;
}
}    public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
}

public static String getString(){
return "这是LoginAction中的一个静态方法";
}

}loginSuc.jsp<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib prefix="s"  uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
    <h1>成功页面</h1>
    名字属性:<s:property value="user.name"/><br>
    密码属性:<s:property value="user.password"/><br> 
    地址属性:<s:property value="user.address.addre"/><br> 
    调用值栈中对象的普通方法:<s:property  value="user.getString()"/><br><br>
    
    调用Action中一个静态方法:<s:property value="@com.action.LoginAction@getString()"/><br>
    调用JDK中的类的静态方法: <s:property value="@java.lang.Math@floor(44.56)"/><br>  
    调用JDK中的类的静态方法:<s:property value="@@floor(44.56)"/><br>
    调用JDK中的类的静态方法:<s:property value="@java.util.Calendar@getInstance()"/><br>  
    调用普通类中的静态属性:<s:property value="@com.dto.Address@TS"/><br>

  </body>
</html>
 
运行成功,以下几处不能显示
    调用Action中一个静态方法:
    调用JDK中的类的静态方法:
    调用JDK中的类的静态方法:
    调用JDK中的类的静态方法: 
    调用普通类中的静态属性:
   各行后面的内容

解决方案 »

  1.   

    <s:property value="@com.action.LoginAction@getString()"/> ?这是啥意思?不用s:property 标签啦,直接改为
    <%=com.action.LoginActio. getString()%>不行吗?
      

  2.   

    在struts.xml中配置启用静态方法调用struts.ognl.allowStaticMethodAccess设置为true 
      

  3.   

    在struts.xml中配置启用静态方法调用 struts.ognl.allowStaticMethodAccess设置为true
      

  4.   

    配置文件中:struts.ognl.allowStaticMethodAccess = true