首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

模拟Struts功能-最后的一些实体bean以及源码上载

2012-11-10 
模拟Struts功能--最后的一些实体bean以及源码下载首先 是Actionpackage com.chusiyou.struts.coreimport

模拟Struts功能--最后的一些实体bean以及源码下载
首先 是Action

package com.chusiyou.struts.core;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Action extends ActionServlet{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
           return mapping.findForward("");
}

}

再就是ActionForm--就是一个类  里面什么都没有,我没有写一些什么验证属性的一些方法,只要完成大体功能就OK
package com.chusiyou.struts.core;

public class ActionForm {



}

管理跳转的一个类,我写的默认是request.getRequestDispatcher(name).forward(request, response)这种跳转方式


package com.chusiyou.struts.core;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ActionForward {
public ActionForward(){

}
public ActionForward(String name,HttpServletRequest request,HttpServletResponse response){
this.tiaozhuan(name,request,response);
}
private void tiaozhuan(String name,HttpServletRequest request,HttpServletResponse response){
try {
request.getRequestDispatcher(name).forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}

ActionMapping 类 辅助ActionForward类 把name属性对应的path传递给ActionForward

package com.chusiyou.struts.core;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ActionMapping {
HttpServletRequest request;
HttpServletResponse response;
ActionMappings actionMappings;
public ActionMapping(){}
public ActionMapping(HttpServletRequest request,HttpServletResponse response,ActionMappings actionMappings){
this.request=request;
this.response=response;
this.actionMappings=actionMappings;
}
public ActionForward findForward(String name){
String path=null;
    for(String str:actionMappings.getForwards().keySet()){
    if(name.equals(str)){
    path=actionMappings.getForwards().get(name);
    }
    }
return new ActionForward(path,request,response);
}

}

管理action 所有配置属性的一个实体类,哎英语太烂,不会起名字 痛苦

package com.chusiyou.struts.core;

import java.util.HashMap;

public class ActionMappings {
private String path;  
private String name;
private String type;
private HashMap<String, String> forwards=new HashMap<String, String>();
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public HashMap<String, String> getForwards() {
return forwards;
}
public void setForwards(HashMap<String, String> forwards) {
this.forwards = forwards;
}


}

//最后一个是管理formbean属性的一个实体类

package com.chusiyou.struts.core;

public class FormBeans {
private String name;
private String type;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}

}


最后是 struts-XML配置文件

<struts-config>
  <form-beans>
      <form-bean name="testrForm" type="com.chusiyou.test.TestForm"></form-bean>
  </form-beans>
  <action-mappings>
       <action path="/test"  name="testrForm" type="com.chusiyou.test.TestAction">
          <forward name="main" path="/main.jsp"></forward>
          <forward name="error" path="/error.jsp"></forward>
      </action>
      <action path="/user" type="com.chusiyou.test.UserAction">
         <forward name="main" path="/main.jsp"></forward>
      </action>
  </action-mappings>
</struts-config>

//所有源文件下载
我上传



热点排行