gpt4 book ai didi

java - Java提供时间戳吗???......DWR

转载 作者:行者123 更新时间:2023-12-02 00:39:08 26 4
gpt4 key购买 nike

我正在使用 DWR,这是我相当新的...我使用 ajax 向页面提交评论,我收到请求查看提交评论时是否可以显示 tmestamp:

简而言之,该 bean 有一个称为可审计的变量...在到达数据库之前,该变量不会填充时间戳。没关系。我的问题...我可以使用ajax将一些东西传递给可审计的东西,这是一种“时间戳”来传递回页面???

提前致谢!!!!

代码如下:

JSP

 You have <strong><span id="commentsCounter">${const['COMMENT_MAX_LENGTH'] - fn:length(commentForm.comment)}</span></strong> characters left.<br/>
<textarea id="comment" name="comment" rows="2" cols="125" style="width:395px;"
onkeypress="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
onkeydown="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
onkeyup="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)">
</textarea>

<a href="javascript:addComment();"><img src="../images/icon_add.gif" border="0" alt="Add"/></a>

DWR JavaScript:

function addComment()
{
$("#commentErrors").css("visibility", "hidden");

var obj = {comment:null};
WhatIfDataAction.addComment(dwr.util.getValues(obj),
{
callback:addCommentCallback,
timeout:60000,
exceptionHandler:function(msg, e)
{
alert("Error submitting form. " + msg);
}
}
);
}


function addCommentCallback( comment )
{
if (comment.messages.length > 0)
{
//Convert the error messages into an HTML string.
var html = "";
for (var i = 0; i < comment.messages.length; i++)
{
html += "<tr><td>" + comment.messages[i] + "</td></tr>";
}
$("#commentErrors").html(html);
$("#commentErrors").css("visibility", "visible");
}
else
{
// Build HTML for new row.
var html = "<tr id='id"+comment.id+"'><td id='comment-"+comment.id+"'class='wrappable'>" + comment.comment + "</td>" +

"<td id='auditable-"+comment.id+"'>" + comment.id + "</td>" +


"</tr>"; // three empty TDs for the three actuals fields
$("#commentRow").before(html);

WHATIFDATAACTION.JAVA:

public CommentForm addComment(Map<String,String> properties) throws Exception
{
CommentForm form = new CommentForm(properties);
if (form.validate(this))
{
CommentBean bean = form.toBean();
EntryBean entry = WhatifCache.fetchEntryFromCache(getSession());

entry.addComment(bean);

form.setId(bean.getId());
bean = form.toBean();

}
return form;
}

最后...commentBean:

public final class CommentBean
extends AbstractBean
implements Auditable,
BeanCache.CacheableBean

{
private long id;
private long entryId;
private String comment;
private AuditableBean auditable;

/** Description character max length, matches size of description field in db **/
public static final Integer COMMENT_MAX_LENGTH = 250;

public CommentBean()
{
}

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
id = in.readLong();
entryId = in.readLong();
comment = in.readUTF();
auditable = (AuditableBean)in.readObject();
}

@Override
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeLong(id);
out.writeLong(entryId);
out.writeUTF((comment == null) ? "" : comment);
out.writeObject( auditable );
}

@Override
public void readSQL(SQLInput in, String typeName) throws SQLException
{
id = in.readLong();
entryId = in.readLong();
comment = in.readString();
auditable = (AuditableBean)in.readObject();
}

@Override
public void writeSQL(SQLOutput out) throws SQLException
{
out.writeLong(id);
out.writeLong(entryId);
out.writeString(comment);
out.writeObject( auditable );
}

public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public long getEntryId()
{
return entryId;
}
public void setEntryId(long entryId)
{
this.entryId = entryId;
}
public String getComment()
{
return comment;
}
public void setComment(String comment)
{
this.comment = comment;
}
public AuditableBean getAuditable()
{
return auditable;
}
public void setAuditable(AuditableBean bean)
{
auditable = bean;
}

public boolean isActive()
{
return true;
}

public String getKey()
{
return ""+id;
}

最佳答案

您是否尝试返回new Date().getTime()?这将为您提供以毫秒精度表示的当前日期。

或者只返回一个格式化的日期字符串,例如 new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS").format(new Date())

关于java - Java提供时间戳吗???......DWR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6859199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com