forked from admin/struts2-demo
34 lines
1004 B
Java
34 lines
1004 B
Java
package com.demo.action;
|
|
|
|
import com.opensymphony.xwork2.ActionSupport;
|
|
|
|
/**
|
|
* Hello World 示例 Action
|
|
* 展示 Struts2 最基础的 Action 写法
|
|
*
|
|
* ActionSupport 提供了:
|
|
* - validate() 方法用于表单验证
|
|
* - getText() 方法用于国际化
|
|
* - addActionError()/addFieldError() 用于错误消息
|
|
*/
|
|
public class HelloAction extends ActionSupport {
|
|
|
|
private String name;
|
|
private String message;
|
|
|
|
@Override
|
|
public String execute() throws Exception {
|
|
// 业务逻辑
|
|
if (name == null || name.trim().isEmpty()) {
|
|
name = "World";
|
|
}
|
|
message = "Hello, " + name + "! 欢迎学习 Struts2!";
|
|
return SUCCESS;
|
|
}
|
|
|
|
// Getter/Setter (Struts2 需要这些来获取/设置参数)
|
|
public String getName() { return name; }
|
|
public void setName(String name) { this.name = name; }
|
|
public String getMessage() { return message; }
|
|
public void setMessage(String message) { this.message = message; }
|
|
} |