模拟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>

//所有源文件下载
我上传
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值