java-web交流群:132607763
Action中有对象属性,表单提交后,action自动为对象赋值。
book类:
package com.mm.entity;
import java.util.Date;
public class Book {
private String name;
private String author;
private Date publishDate;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Date getPublishDate() {
return publishDate;
}
public void setPublishDate(Date publishDate) {
this.publishDate = publishDate;
}
public String toString() {
return this.name + ":" + this.author + ":" + this.publishDate;
}
}
action类
package com.mm.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
import com.mm.entity.Book;
@ParentPackage("struts2Test")
public class BookAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String title;
private Book book;
@Action(value = "addBook", results = { @Result(name = SUCCESS, location = "/book.jsp") })
public String add() {
System.out.println(book);
title = "添加成功";
return SUCCESS;
}
@Action(value = "clear", results = { @Result(name = SUCCESS, location = "/book.jsp") })
public String clear() {
title = "清空了";
return SUCCESS;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
}
jsp页面:
<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/struts-dojo-tags" prefix="sd" %>
<!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=ISO-8859-1">
<title>${title}aa</title>
<sd:head parseContent="true"/>
</head>
<body>
<s:form action="addBook">
<s:label value=" 添加图书"></s:label>
<s:textfield name="book.name" label="书名:"></s:textfield>
<s:textfield name="book.author" label="作者"></s:textfield>
<sd:datetimepicker name="book.publishDate" label="出版时间"></sd:datetimepicker>
<s:submit value="提交"></s:submit>
</s:form>
</body>
</html>
分享到:
相关推荐
使用反射自动装填前台数据和struts自动装填很像,实现了struts自动装填对象的原理
在struts2中已经不需要struts1中的formbean了。...属性名来给对象赋值,然后操作这个对象。而这些对象都是vo的实现,如果使用hibernate,可以直接把struts2的vo和hibernate的po整合到一块,直接使用一个即可。
struts2 配置dtd 自动提示 struts2 配置dtd 自动提示
但是,在开发工作中,对功能的升级是基于既定架构是很常见的情况。本人碰到需要用开发基于Struts2的HTTP+JSON返回... Struts2返回JSON有两种方式:1.使用Servlet的输出流写入JSON字符串;2.使用Struts2对JSON的扩展。
Struts2获得Response对象的四种方法 Struts2 是一个基于MVC 模式的 Web 应用程序框架,它提供了多种方式来获取 Response 对象,以下是四种获得 Response 对象的方法: 方法 1:使用 Struts2 Aware 拦截器 在 ...
Struts开发中有哪几个关键对象,并分别说出这些关键对象的作用?
struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别...
struts2的自动构建,通过sql创建实体类和XXMapper.xml文件
此文件可直接导入测试使用,供初学struts2的朋友借鉴,包含struts2类中获得内置对象,注入form表单参数,struts2的基本XML配置等等...
类似百度和淘宝搜索框,输入一部分内容,自动联想相关内容,点击下拉框条目自动完成文本框输入。其中同时包括不通过struts2获取数据的实现方法。参考网址http://jqueryui.com/autocomplete/
Struts2的Struts.xml自动提示文件,配置欧克后,Struts2就能在无网络情况下自动提示代码。
struts2 获取request session对象
spring自动装配项目struts2,使用了struts2 ,spring2.5 ,hibernate,和spring 自动装配
Struts2+JSON_实现AJAX_返回对象和列表
Struts2返回JSON对象. 通过Struts2框架返回json对象,更好传递数据
Struts 2 Action对象为每一个请求产生一个实例,因此没有线程安全问题。 3 Servlet依赖方面的对比:Struts 1 Action依赖于Servlet API,因为Struts 1 Action的execute方法中有HttpServletRequest和...
struts例子struts例子struts例子struts例子struts例子struts例子struts例子struts例子struts例子struts例子struts例子struts例子struts例子struts例子struts例子
NULL 博文链接:https://zywang.iteye.com/blog/413003
NULL 博文链接:https://lzj0470.iteye.com/blog/1941682
struts1和struts2的区别其实并不是太大,两者的区别: Action 类: ◆Struts1要求Action类继承一个抽象基类。...Action接口不是必须的,任何有execute标识的POJO对象都可以用作Struts2的Action对象。