struts2-byblank案例练习(二)封装表单数据
前言:本文对案例练习一拓展,进行数据封装,并实现表单校验。
数据封装
1 修改struts.xml配置,将action添加class属性
<package name="default" namespace="/" extends="struts-default"> <action name="HelloWorld" class="action.HelloWorldAction"> <result>HelloWorld.jsp</result> </action> </package>
2 创建HelloWorld.java文件
package action; import com.opensymphony.xwork2.ActionSupport; public class HelloWorldAction extends ActionSupport{ private String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } @Override public String execute() throws Exception { setMessage("hello,world! 我来自HelloWorldAction.java"); return SUCCESS; } }
3,修改HelloWorld.jsp,引入struts2标签库。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>HelloWord</title> </head> <body> <h1><s:property value="message"/></h1> </body> </html>
运行结果
相关推荐
Plant 2020-05-31
liulufei 2020-05-09
hygbuaa 2020-04-30
TreasureZ 2020-02-22
russle 2016-11-18
ajaxtony 2019-10-28
popohopo 2013-03-02
xyzxiafancai 2017-04-21
russle 2016-11-18
cyydjt 2013-07-09
智小星 2019-06-28
simon曦 2010-10-20
XTUxiaoxin 2014-02-28
86193951 2019-06-18
aspshipin 2013-10-06
xianzhe 2019-06-21
simon曦 2007-07-11