Update: web.xml and generated files
This commit is contained in:
34
web/WEB-INF/classes/com/demo/action/HelloAction.java
Normal file
34
web/WEB-INF/classes/com/demo/action/HelloAction.java
Normal file
@@ -0,0 +1,34 @@
|
||||
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; }
|
||||
}
|
||||
Reference in New Issue
Block a user