package org.swj.site.util; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelUtil { public List<String> readExcel(File excelFile,int sheetNum,int rowNum,int cellNum) { XSSFWorkbook wb; List<String> result = new ArrayList<String>(); try { wb = new XSSFWorkbook(new FileInputStream(excelFile)); XSSFSheet sheet = wb.getSheetAt(sheetNum); int totalRows = sheet.getLastRowNum(); for(int i = rowNum; i <= totalRows; i++) { XSSFRow row = sheet.getRow(i); if(row == null) { continue; } int totalCells = row.getLastCellNum(); System.out.println(totalCells); StringBuffer sb = new StringBuffer(); for(int j=cellNum;j < totalCells;j++){ sb.append(row.getCell(j).toString()).append(","); } result.add(sb.toString()); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; } } package org.swj.site.web; import java.io.File; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import org.swj.site.domain.Staff; import org.swj.site.service.StaffService; import com.opensymphony.xwork2.ActionSupport; public class StaffAction extends ActionSupport { private static final long serialVersionUID = 1L; private File file; private String sheet; private String row; private String cell; private Staff staff; private StaffService staffService; public void setStaff(Staff staff) { this.staff = staff; } public Staff getStaff() { return staff; } public void setStaffService(StaffService staffService) { this.staffService = staffService; } public File getFile() { return file; } public void setFile(File file) { this.file = file; } public String getSheet() { return sheet; } public void setSheet(String sheet) { this.sheet = sheet; } public String getRow() { return row; } public void setRow(String row) { this.row = row; } public String getCell() { return cell; } public void setCell(String cell) { this.cell = cell; } public String index() throws Exception { return SUCCESS; } public String upload() throws Exception { if(file == null){ return INPUT; } int sheetNum = Integer.parseInt(sheet); int rowNum = Integer.parseInt(row); int cellNum = Integer.parseInt(cell); staffService.insertStaff(file,sheetNum,rowNum,cellNum); staff.setStaffNo(""); staff.setStaffName(""); staff.setStatus(""); List<Staff> list = staffService.selectAllStaff(staff); HttpServletRequest request = ServletActionContext.getRequest(); request.setAttribute("staff",list); return SUCCESS; } public String list() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); System.out.println("--------"+staff.getStaffNo()); System.out.println("--------"+staff.getStaffName()); System.out.println("--------"+staff.getStatus()); String action = request.getParameter("action"); if("renounce".equals(action)){ String staffNo = request.getParameter("staffNo"); staff.setStaffNo(staffNo); staff.setStatus("none"); staffService.updateStaff(staff); //staff = null; } List<Staff> list = staffService.selectAllStaff(staff); request.setAttribute("staff",list); return SUCCESS; } public String lottery() throws Exception { return SUCCESS; } } <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.objectFactory" value="spring"/> <constant name="struts.ognl.allowStaticMethodAccess" value="true"/> <constant name="struts.i18n.encoding" value="UTF-8"/> <constant name="struts.devMode" value="false"/> <include file="web-config.xml"></include> </struts> <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap namespace="Staff"> <typeAlias alias="Staff" type="org.swj.site.domain.Staff"/> <resultMap id="staffResult" class="Staff"> <!-- <result property="staffId" column="STAFFID"/> --> <result property="staffNo" column="STAFFNO"/> <result property="staffName" column="STAFFNAME"/> <result property="staffDepartment" column="STAFFDEPARTMENT"/> <result property="status" column="STAFFSTATUS"/> </resultMap> <parameterMap id="staffParameter" class="Staff"> <parameter property="staffNo" jdbcType="VARCHAR2"/> <parameter property="status" jdbcType="VARCHAR2"/> </parameterMap> <insert id="insertStaff" parameterClass="Staff"> INSERT INTO T_STAFF (STAFFNO,STAFFNAME,STAFFDEPARTMENT,STAFFSTATUS) VALUES (#staffNo#,#staffName#,#staffDepartment#,#status#) </insert> <select id="selectStaff" parameterMap="staffParameter" resultMap="staffResult"> SELECT STAFFNO,STAFFNAME,STAFFDEPARTMENT,STAFFSTATUS FROM T_STAFF WHERE 1=1 <isNotEmpty prepend="AND" property="staffNo"> STAFFNO = #staffNo# </isNotEmpty> <isNotEmpty prepend="AND" property="staffName"> STAFFNAME = #staffName# </isNotEmpty> <isNotEmpty prepend="AND" property="status"> STAFFSTATUS = #status# </isNotEmpty> </select> <update id="updateStaff" parameterClass="Staff"> UPDATE T_STAFF SET STAFFSTATUS = #status# WHERE STAFFNO = #staffNo# </update> </sqlMap> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> <action name="index" method="index" class="staffAction"> <result name="success">page/jsp/index.jsp</result> </action> <action name="upload" method="upload" class="staffAction"> <interceptor-ref name="fileUpload"> <param name="allowedTypes"> application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel </param> <param name="maximumSize">10485760</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> <result name="input">/page/jsp/fileUpload.jsp</result> <result name="success">/page/jsp/display.jsp</result> </action> <action name="list" method="list" class="staffAction"> <result name="success">/page/jsp/display.jsp</result> </action> <action name="lottery" method="lottery" class="staffAction"> <result name="success">/page/jsp/lottery.jsp</result> </action> </package> </struts>
详细解决方案
spring+struts2+dwr 二
热度:449 发布时间:2013-01-05 15:20:39.0
相关解决方案
- struts2.xml的action中的result报错,该怎么处理
- (Struts2+JSON+Ajax) XMLHttpRequest ==500如何解决
- struts2 对象属性流入不进去, 报错:target is null for setProperty(null, "x" [Ljava.lang.Stri
- Spring MVC开发模式,怎么取得新增的id
- Struts2 <select>上拉框 回显有关问题
- spring 表单对象绑定有关问题 String与Long的转换
- struts2 添加和修改怎么在一个jsp页面实现
- struts2 查询输出的有关问题
- spring+quartz定时器有关问题
- 零配置的有关问题(struts2+Hibernate)
- spring @Scope("prototype")注解更新有关问题,寻求帮助
- struts2 神奇有关问题,太神奇了!
- Spring MVC是不是可以完全取代Struts
- spring+quartz的错误,不能正常启动
- spring mvc +ibatis+db2连接数据库的配置如何写啊小弟我链接不下
- struts2 的<s:iterator>标签展示未完全初始化的数组出现奇怪的有关问题
- spring MVC cvc-complex-type.2.4.c解决方案
- Spring + Mybatis 组合报错
- struts2 文件下传有关问题
- Spring 中 packagesToScan有关问题
- struts2+ajax请求失败,帮忙看一上
- struts2-json中诠注@JSON(deserialize=false)是什么用?不是阻止JSON反序列化成JAVA对象吗?求解
- Spring MVC中点击旋钮没反应
- spring aop这个跳转异常是咋回事
- spring security3的一个小疑点。加急
- struts2 循环累加属性值有关问题
- struts2,hibernate,spring3 常用框架的API CHM版本,该怎么处理
- spring 事务 aop transactionManager,该怎么解决
- struts2 将jsp回到到另一个jsp中
- Spring 事务管理,该怎么处理