struts2学习笔记(2)
部署好struts2的hello world项目后,看下它的目录结构
?该项目做了4件事:
MessageStore.java
package org.apache.struts.helloworld.model;public class MessageStore {private String message;public MessageStore() {setMessage("Hello Struts User");}public String getMessage() {return message;}public void setMessage(String message) {this.message = message;}}
?model类,注意它的getter和setter,struts2在表现(视图层)需要调用相应的getter和setter方法
?
HelloWorldAction.java
package org.apache.struts.helloworld.action;import org.apache.struts.helloworld.model.MessageStore;import com.opensymphony.xwork2.ActionSupport;public class HelloWorldAction extends ActionSupport {private static final long serialVersionUID = 1L;private MessageStore messageStore;public String execute() throws Exception {messageStore = new MessageStore() ;return SUCCESS;}public MessageStore getMessageStore() {return messageStore;}public void setMessageStore(MessageStore messageStore) {this.messageStore = messageStore;}}
?这是一个控制器,用户的一个行为可能会调用一个或多个控制器,并且返回一个String型的结果,一个特定的视图会被渲染