我想做一個簡易的留言版程式,但遇到了些問題
我想利用JSP這裡的submit去把下面四個所填上的資料,帶到下一個頁面
以及把資訊顯示在console裡。
但我怎麼嘗試都沒有辦法,請問我是哪裡需要修改嗎?
這是JSP CODE:
<body>
<form>
<table width="512 px" border="1">
<tr>
<td>ID</td>
<td><s:textfield name="entity.id" /></td>
</tr>
<tr>
<td>留言人</td>
<td><s:textfield name="entity.createowner" /></td>
</tr>
<tr>
<td>留言主題</td>
<td><s:textfield name="entity.subject" /></td>
</tr>
<tr>
<td>留言內容</td>
<td><s:textfield name="entity.message" /></td>
</tr>
<tr>
<td>
<button type="button" onclick="insert()">留言</button>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function insert() {
document.forms[0].submit(); /*確認提交目前網頁第一個form元素*/
}
</script>
</body>
</html>
這是我的Action.java CODE:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class MessageAction extends MessageValue {
static final Logger log = LogManager.getLogger(MessageAction.class);
public String ADD() throws Exception {
MessageValue message = new MessageValue();
log.info(message.getId());
log.debug(message.getSubject());
log.error(message.getMessage());
log.info(message.getCreateowner());
return "success";
}
private MessageAction messageAction;
public MessageAction getMessageAction() {
return messageAction;
}
public void setMessageAction(MessageAction messageAction) {
this.messageAction = messageAction;
}
}
還有Value.java CODE:
import java.util.Date;
public class MessageValue {
private int Id;
private String Subject;
private String Message;
private Date Createdate;
private String Createowner;
public MessageValue(){}
public MessageValue (int Id, String Subject, String Message, Date Createdate, String Createowner){
this.Id = Id;
this.Subject = Subject;
this.Message = Message;
this.Createdate = Createdate;
this.Createowner = Createowner;
}
Value我已經設置好getter & setter了