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";
}