问题描述
struts.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "http://struts.apache.org/dtds/struts-2.1.7.dtd"><struts><package name="demo" extends="struts-default"><action name="department_*" class="org.lzh.action.DepartmentAction" method="{1}"><result name="goadddepartment">/department_add.jsp</result><result name="godepartment">/department.jsp</result><result name="goindex" type="chain">department_goDepartment</result></action></package></struts>department.jsp<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!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"></head><body><table><tr><th><a href="department_goDepartment.action">部门管理</a> | <a href="department_add.jsp">部门添加</a> | 查询:姓名<input/>年龄<input/>性别<input type="button" value="查询"/></th></tr></table><table width="100%"><tr><th width="40">选中</th><th width="140">部门名称</th><th width="80">员工数量</th><th>部门简介</th><th width="120">操作</th></tr><tr><td align="center"><input type="checkbox"/></td><td align="center"></td><td align="center"></td><td></td><td><a href="">修改</a> | <a href="">删除</a></td></tr><tr><td colspan="5"><a href="">选中</a> | <a href="">反选</a> | <input type="button" value="批量删除"/></td></tr></table></body></html>department_add.jsp<%@ 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>Insert title here</title></head><body><s:form action="department_doAddDepartment"><s:textfield label="部门名称 " name="department.departName"></s:textfield><s:textfield></s:textfield></s:form></body></html>DepartmentActionpackage org.lzh.action;import com.opensymphony.xwork2.ActionSupport;public class DepartmentAction extends ActionSupport {private static final long serialVersionUID = 4206132592553228995L;public String goAddDepartment()throws Exception{return "goadddepartment";}public String goDepartment()throws Exception{return "godepartment";}public String doAddDepartment()throws Exception{return "goindex";}}Departmentpackage org.lzh.model;import java.io.Serializable;import java.util.Set;public class Department implements Serializable {private static final long serialVersionUID = 7141725355658427077L;private Integer id;private String departName;private String departIntrot;private Integer staffNumber;private Set<Staff> staffs;public String getDepartIntrot() {return departIntrot;}public void setDepartIntrot(String departIntrot) {this.departIntrot = departIntrot;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getDepartName() {return departName;}public void setDepartName(String departName) {this.departName = departName;}public Integer getStaffNumber() {return staffNumber;}public void setStaffNumber(Integer staffNumber) {this.staffNumber = staffNumber;}public Set<Staff> getStaffs() {return staffs;}public void setStaffs(Set<Staff> staffs) {this.staffs = staffs;}}
解决方案
type="redirect"