Helloworld 入门实例(3)

package com.wuyudong.helloworld.model; public class MessageStore { private String message; public MessageStore(String msg){ this.setMessage(msg); } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }

创建Action类HelloWorldAction,充当Controller

package com.wuyudong.helloworld.action; import com.opensymphony.xwork2.ActionSupport; import com.wuyudong.helloworld.model.MessageStore; public class HelloWorldAction extends ActionSupport { private static final long serialVersionUID = -4958566543551999157L; private MessageStore msgStore; @Override public String execute() throws Exception { msgStore = new MessageStore("HelloWorld!"); return SUCCESS; } public MessageStore getMsgStore() { return msgStore; } public void setMsgStore(MessageStore msgStore) { this.msgStore = msgStore; } }

配置web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee " id="WebApp_ID" version="3.0"> <display-name>12.01</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>

运行后如图所示

Helloworld 入门实例

Helloworld 入门实例

推荐阅读:

Struts中异步传送XML和JSON类型的数据

Struts2的入门实例

Struts2学习笔记-Value Stack(值栈)和OGNL表达式   

struts2文件上传(保存为BLOB格式)

Struts2的入门实例

Struts2实现ModelDriven接口

遇到的Struts2文件下载乱码问题

Struts2整合Spring方法及原理

Struts2 注解模式的几个知识点

Struts 的详细介绍请点这里
Struts 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b112a24746b5e5432bb6c8ef2ab51a25.html