struts2上传学生 csv数据文件 到数据库
上传的jsp页面<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/page/share/taglib.jsp" %>
<%@ include file="/WEB-INF/page/share/studentSelectAll.jsp"%>
<html>
<head>
<title>学生基本信息上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/vip.css" type="text/css">
<link href="css/admin.css" rel="stylesheet" type="text/css"/>
<SCRIPT language=JavaScript src="js/FoshanRen.js"></SCRIPT>
<script language="JavaScript">
function myFormCheck(theform)
{
if(theform.file.value=="")
{
alert("请点击浏览按钮,选择您要上传的文件!")
theform.file.focus;
return false;
}
else
{
str= theform.file.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
if(extname!=".csv")
{
alert("请选择csv文件!")
return false;
}
//// if(extname!=".xls")
//// {
// / alert("请选择excel文件!")
/// return false;
//// }
}
}
</script>
</head>
<body style="text-align:center">
<div id="header"><%@include file="../share/header.jsp" %></div>
<div id="center">
<div id="left">
<jsp:include page="../share/leftMenu_Admin.jsp"/>
</div> <!-- 左边的left -->
<div id="center_in">
<s:form action="control/student_fileUpload" theme="simple" enctype="multipart/form-data" method="post" onsubmit="return myFormCheck(this)">
<table width="100%" border="0" cellspacing="2" cellpadding="3" align="center">
<tr bgcolor="6f8ac4"><td colspan="2" > <font color="#FFFFFF">上传学生信息表::</font></td>
</tr>
<tr bgcolor="f5f5f5">
<td width="22%" ><div align="right">请选择csv文件:</div></td>
<td width="78%">
<s:file name="file" id="file"></s:file>
</td>
</tr>
<tr bgcolor="f5f5f5">
<td></td>
<td>
<input type="submit" name="SYS_SET" value="导入" class="frm_btn">
</td>
</tr>
</table>
</s:form>
</div>
</div>
</body>
</html>
struts.xml里面的action自己配置,studentAction中 fileUpload方法的处理
import com.csvreader.CsvReader;
导入javacsv.jar<