⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listenmainaction.java

📁 中应用程序的访问权限对Java Web Console 中应用程序的访问权限 成功登录 Web 控制台后,可能无法自动访问在该控制台中注册的所有应用程序。通常,必须安装应用程序,才能让所有的用户在控制
💻 JAVA
字号:
package edu.yinhe.mis.control;

import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;

import edu.yinhe.mis.dto.ListenmainDTO;
import edu.yinhe.system.common.AppException;
import edu.yinhe.system.control.BaseAction;
public class ListenmainAction extends BaseAction{
	/**
	 * @author wanjiansheng
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return forward
	 * @throws ServletException 
	 * 导入听课的Excel表
	 */
	public ActionForward teamerFillin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		ActionForward forward=null;
		ListenmainForm lmf=(ListenmainForm)form;
		FormFile formFile=lmf.getListenfile();
		String fileName=formFile.getFileName();
		//Configuration conf=new Configuration();
		fileName=fileName.substring(fileName.lastIndexOf("."));
		fileName=System.currentTimeMillis()+fileName;//当前时间加文件名保证表的唯一性
		//String savePath=conf.getProperty("uploadSavePath");
		fileName="c:\\"+fileName;
		//System.out.println(fileName+"******************************************");

		try {
			FileOutputStream fout=new FileOutputStream(fileName);
			BufferedInputStream fin=new BufferedInputStream(formFile.getInputStream());
			//FileInputStream fin=formFile.getInputStream();
			byte[] bytes=new byte[1024*2];
			int i=0;
			while((i=fin.read(bytes, 0, bytes.length))!=-1){
				fout.write(bytes, 0, i);
			}
			fout.flush();
			fout.close();
			fin.close();


			//读文件并采集数据,装入到List集合中;
			//插入到数据库中,
			ListenmainExcel excel = new ListenmainExcel();
			ArrayList list = excel.readExcel(fileName);// 把excel文件解析出来封装在ArrayList里
			//System.out.println(list.size() + "list.size()");
			for (int j = 0; j < list.size(); j++) {
				ListenmainDTO dto = (ListenmainDTO) list.get(j);// 把ArrayList里的数据放到DTO里
				//list=(ArrayList)service.findAll();//调用服务层的方法
				Boolean flag=false;
				try {
					service.setDataSource(getDataSource(request,"mydatasource"));//设置连接,固定写法,这个service是从BaseAction继承过来
					flag = (Boolean) service.create(dto);// 把数据插入到数据库的表excel里
				} catch (AppException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if (flag) {
					forward=mapping.findForward("teamerFillin");
				} else {
					forward=mapping.findForward("/error.jsp");
				}
			}

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return forward;
	}
	/**
	 * @author wanjiansheng
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return forward
	 * 查询听课记录表
	 */
	public ActionForward teamerQuery(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ListenmainForm lmf = (ListenmainForm) form;
		ListenmainDTO  lmd =new ListenmainDTO();
		String startDate=request.getParameter("startDate");
		String endDate=request.getParameter("endDate");
		String teacher =request.getParameter("teacher");
		if(startDate!=null&&!"".equals(startDate))
		{
			lmd.setStartDate(startDate);
			lmd.setEndDate(endDate);
		}
		if(teacher!=null&&!"".equals(teacher)){
			

			lmd.setTeacher(teacher);
		}		
		ActionForward forward=null;
		List list=new ArrayList();
		try {
			BeanUtils.copyProperties(lmd, lmf);
			service.setDataSource(getDataSource(request,"mydatasource"));
			list=(List) service.alllist(lmd);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(list!=null){
			request.setAttribute("listenmain", list);
			request.setAttribute("dto", lmd);
			forward=mapping.findForward("teamerQuery");
		}else{
			System.out.println("ERROR!");
		}

		return forward;

	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -