<%@page contentType="text/html" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%><html>
<head>
<title>Div 演示</title>
<sx:head />
</head>

<body>
<sx:div cssStyle="border:1px solid black;height:25px;width:500px"
href="ServerTime" updateFreq="1000" highlightColor="#ffcdee">
  服务器当前时刻
</sx:div>
</body>
</html>
    <package name="default"  extends="struts-default">
        <action name="ServerTime" class="com.struts2.ServerTime">
            <result>servertime.jsp</result>
        </action>
servertime.jsp 是返回的数据,内容是:${currentTime}
${requestScope.currentTime}
ServerTime action 就做了一个传值ublic class ServerTime extends ActionSupport {
private String currentTime; public String getCurrentTime() {
return new Date().toString();
} public void setCurrentTime(String currentTime) {
this.currentTime = currentTime;
}}
-------------
计划在 div 中显示 时间字符串。但实际显示的却是 ${currentTime} ${requestScope.currentTime} 
这是怎么回事?

解决方案 »

  1.   

     div 中应该显示一个时间,比如 Sat Mar 13 04:05:48 CST 2010 。它应该是 ServerTime Action 通过值栈传过来的 Action 的那个属性值 currentTime。  可是返回的数据显式出来只是“${currentTime} ${requestScope.currentTime}”,而不是生成的时间字符串。我页面里有isELIgnored="false",为什么不能解析 ${currentTime}? 
      

  2.   

    看看jsp的版本支持EL表达式吗
      

  3.   

    我有看了一个例子,里头的action 是这么写的。public class GetDate extends ActionSupport{
    private Date now;

    public Date getNow() {
    return now;
    } public void setNow(Date now) {
    this.now = now;
    } public String execute() throws Exception{
    now = new Date();
    return SUCCESS;
    }
    }
      

  4.   

    不是因为没有execute方法,是因为servertime.jsp 写得太简单,根本就没解析这个表达式就返回了,虽说ajax只需要数据而不需要全部页面。 这种表达式-- ${currentTime},应该计算完了才能显示出来。所以servertime.jsp 修改一下就行了。
    <%@ page language="java" pageEncoding="gb2312" isELIgnored="false"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    </head>
      
    <body>
    服务器当前时间为:<font color="red"><s:date name="now" format="yyyy-MM-dd HH:mm:ss"/></font>
    <br>
    服务器当前时间为:<font color="red">${currentTime}</font>
    </body>
    </html>package com.struts2;import com.opensymphony.xwork2.ActionSupport;
    import java.util.Date;public class ServerTime extends ActionSupport {
    private String currentTime;
        private Date now;
        
        public Date getNow() {
            //return now;
         return now = new Date();
        }    public void setNow(Date now) {
            this.now = now;
        } public String getCurrentTime() {
    //return currentTime;
    return currentTime = new Date().toString();
    } public void setCurrentTime(String currentTime) {
    this.currentTime = currentTime;
    }/* public String execute() throws Exception {      //没这个也没关系。
    currentTime = new Date().toString();
    now = new Date();
    return this.SUCCESS;
    }*/
    }