struts第五天----给action方法中注入值

来源:互联网 发布:肉炖久了吃好吗 知乎 编辑:程序博客网 时间:2024/06/08 03:25

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
 <constant name="struts.action.extension" value="do"/> 
 <include file="department.xml"/>
 <include file="employee.xml"/>
</struts>   
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
  
 <package name="department" namespace="/control/department" extends="struts-default">
  <action name="list_*" class="com.isoftstone.study.HelloWorldAction" method="{1}">
   <param name="savepath">department</param> 
   <result name="success">/WEB-INF/page/message.jsp</result> 
  </action>  
 </package> 
</struts>   

package com.isoftstone.study;

import com.isoftstone.domain.Person;

 

public class HelloWorldAction {
 private String msg;

 private int id;
 private String name;
 
 private Person person;
 public Person getPerson() {
  return person;
 }

 

 public void setPerson(Person person) {
  this.person = person;
 }

 

 public int getId() {
  return id;
 }

 

 public void setId(int id) {
  this.id = id;
 }

 

 public String getName() {
  return name;
 }

 

 public void setName(String name) {
  this.name = name;
 }

 

 public String getMsg() {
  return msg;
 }

 

 public void setMsg(String msg) {
  this.msg = msg;
 }

 public String addUI(){
  
  msg="addUI";
  return "success";
 }

 public String execute() throws Exception{
  msg="success";
  return "success";
 }
}


package com.isoftstone.domain;

public class Person {
 private int id;
 private String name;
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 

}

 

package com.isoftstone.domain;

public class Person {
 private int id;
 private String name;
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 

}

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>   
    <title>My JSP 'index.jsp' starting page</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 
  </head>
 
  <body>
    <%=new Date() %>中国
    <form action="<%=request.getContextPath() %>/control/employee/list_execute.do"} method="post">
     id:<input name="person.id" type="text"/><br/>
     name:<input name="person.name" type="text"/><br/>
     <input value="发送" type="submit"/>
    </form>
  </body>
</html>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'message.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

  </head>
 
  <body>
    id=${person.id}<br/>
    id=${person.name }
  </body>
</html>

 

原创粉丝点击