Struts2的一套比较清晰的习惯


Struts的业务配置文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<package name="baseManage" namespace="/base" extends="struts-default">
		<action name="group_*" class="groupAction" method="{1}">
			<result name="list">/WEB-INF/jsp/base/listGroup.jsp</result>
			
			<result name="create">/WEB-INF/jsp/base/createGroup.jsp</result>
			<result name="listGo" type="redirect">group_list.action</result>
		</action>
		
		<action name="public_*" class="publicAction" method="{1}">
			<result name="list">/WEB-INF/jsp/base/listEmails.jsp</result>
			<result name="listGo" type="redirect">public_list.action</result>
			
			<result name="view">/WEB-INF/jsp/base/viewExcel.jsp</result>
		</action>	
	</package>
	
</struts>


前端jsp页面请求url:

<a οnclick="location='../base/group_modify.action?id=<s:property value="#groupDTO.id"/>'" href="#">编辑</a>


前端jspAjax请求处理:

function doChanage(tag){
	$.ajax({
		type: "POST",
		url: "../base/public_isChanage.jhtml",
		success: function(msg){
		msg = $.trim(msg);
		if(msg == '1'){
		   alert('采集数据同步完成 !');
		   location='../base/public_list.jhtml';
		}
	}	
});		


Struts action处理程序:

	/**
	 * 增加页面加载
	 * @return
	 */
	public String create() throws Exception{	
		HttpServletRequest request = ServletActionContext.getRequest();
		String val = request.getParameter("val")==null?"":request.getParameter("val");
		//val = new String(val.getBytes("ISO-8859-1"), "utf-8");
		
		if("excel".equals(val)){
			return "createE";
		}
		if("input".equals(val)){
			request.setAttribute("id", 0);
			return "createI";
		}
		return "listGo";
	}	
	
	/**
	 * 增加业务处理
	 * @return
	 */
	public String inputExl() throws Exception{	
		try {
			HttpServletRequest request = ServletActionContext.getRequest();

			InputStream is = new FileInputStream(myFile);

			//获取excel文件列表数据
			List<Map> maps = readXlss("",is,1,14);
			System.out.println("#Log ["+maps.size()+"] "+System.currentTimeMillis());
			
			
			ServletActionContext.getResponse().setContentType("text/html;charset=utf-8"); 
			PrintWriter out = ServletActionContext.getResponse().getWriter();
			out.println(" <script language=\"JavaScript\" type=\"text/JavaScript\">alert('Excel批量导入成功 !');window.close();window.opener.location.reload();self.opener.location.reload();</script> ");
			
			return null;
		
		} catch (Exception e) {System.out.println("#Error ["+e.getMessage()+"] "+System.currentTimeMillis());}
		return "listGo";
	}	





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值