2012-05-16 38 views
0

我已經用jsp支柱bean標籤庫:如何在成功驗證後保留數據?

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 

    <link rel="stylesheet" type="text/css" href="css/stylesheet.css"> 

</head> 
<body> 
<p><a class="colorGrey" href="Welcome.do"> 
    <bean:message key="menu.label" /> 
</a> &gt;&gt;<bean:message key="menu.link.addnews" /> </p> 
<p><br> 
</p> 

<html:form action="/NewsSave"> 
<table width="100%" border="0"> 
<tr> 
<td class="colorGrey" width="164" height="35"> 
    <bean:message key="body.news.title" /> </td> 
<td width="577"> 
    <html:text property="newsTitle" size="40" value=""/> </td> 

</tr> 
<tr> 
<td colspan="2"> 
    <html:errors property="newstitle" /> 
</td> 
</tr> 
<tr> 
<td class="colorGrey"> 
    <bean:message key="body.news.date" /> </td> 
<td> 
    <html:text property="newsDate" size="10" value=""/> </td> 
</tr> 


<tr> 
<td height="21" colspan="2" valign="top"> 
    <html:errors property="newsdate" /> 
</td> 
</tr> 
<tr> 
<td class="colorGrey" height="61" valign="top"> 
    <bean:message key="body.news.brief" /> </td> 
<td valign="top"> 
    <html:textarea property="brief" cols="40" rows="6" value=""/> 
</td> 
</tr> 

<tr> 
<td height="23" colspan="2" valign="top"><html:errors property="brief" /></td> 
</tr> 
<tr> 
<td class="colorGrey" height="100" valign="top"> 
    <bean:message key="body.news.content" /> 
</td> 
<td valign="top"> 
    <html:textarea property="content" cols="40" rows="12" value=""/> 
</td> 
</tr> 
<tr> 
<td height="23" colspan="2" valign="top"> 
    <html:errors property="content" /> 
</td> 
</tr> 
</table> 

<html:submit value="SAVE"/> 
</html:form> 
<form method="POST" 
action="Link.do?method=newsList" 
onsubmit="return confirm('<bean:message key="body.onsubmit.cancel" />')"> 
<input type="submit" value="CANCEL"> 
</form> 

我使用驗證器插件,這意味着,在收到不正確的信息後,它給消息波紋管的文本字段告訴什麼是錯的。但問題是,提交後所有內容都會消失。所以它沒有在texttext-area標籤中的信息。我知道這是因爲value=""。但是我有另外一個頁面,它們有相同的字段來添加信息,這應該從一開始就清楚。如果我刪除value="",則轉發後,此字段中的信息將顯示在該頁面上。所以

  1. 我應該怎麼做,以清除表格中的信息後,轉發到 另一頁?
  2. 如何在成功驗證後保留信息?

回答

1

如上所述,您應該刪除value =「」,因爲這是將字段設置爲空。如果你想清除這些值,那麼你應該在填充你的Form bean的Action類中執行此操作。
如果您發現您的表單bean在請求之間保留其值,請檢查它們是否爲請求範圍:action元素的scope屬性應該是struts.config中的「請求」

+0

感謝您的回答。明白了,現在完美 – And

+0

順便說一句,關於範圍的信息是關鍵 – And

相關問題