Sturts的文件上传

Struts批量上传学生信息
本文介绍了一个使用Struts框架实现的学生信息批量上传功能。通过上传特定格式的TXT文件,系统能够自动解析并批量创建学生账号。此外,还提供了选择学生类型及关联课程的功能。



---------------------------------------------------------------------------------- struts
<action name ="uploadStudent" class ="StudentUploadAction">
<interceptor-ref name ="fileUploadStack" />
<interceptor-ref name="defaultStack"/>
<result type="chain">showBatchUploadCourse</result>
<result name="input">/index.jsp</result>
</action>

<s:form action="" enctype="multipart/form-data">
----------------------------------------------------------------------------------- jsp
<%@ page language="java"
import="java.util.*,com.qieast.platform.model.*"
contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<base href="<%=basePath%>">

<title>七易网络课堂体验 - Powered by 七易科技</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<!--<link rel="stylesheet" type="text/css" href="styles.css">-->


<script language="javascript" type="text/javascript"
src="js/admincp/checkall.js"></script>

</head>
<body>
<s:include value="../../../inc/stdspacetop.jsp"></s:include>
<div class="mainarea">
<div class="maininner">
<s:include value="../../../inc/studenttop.jsp"></s:include>


<s:form action="s/uploadStudent.action?adminid=1" enctype="multipart/form-data">


<div class="bdrcontent">
<table class="formtable">
<tbody>
<tr>
<th style="width: 15em;">上传学员文件:</th>
<td>

<s:file name ="myFile" label ="Image File" /><font color=red>*</font><br/>

文件格式必须为TXT文件,中间分割符为英文半角逗号","。 你还可以<a
target="_blank" href="./data/studentinput_template.txt">点击这里下载模板文件</a>。
</td>
</tr>
<tr>
<th style="width: 15em;">该批学员类型:</th>
<td><input name="studentutype" type="radio" value="1"
onclick="window.location.href='s/showBatchUploadCourse.action?adminid=1'"
checked />
收费学员          
<input name="studentutype" type="radio" value="2"
onclick="window.location.href='s/showBatchUploadRemedy.action?adminid=1'" />
补课学员 <font color="red">*</font>
</td>
</tr>

<tr>
<th style="width: 15em;">学员文件模板:</th>
<td></td>
</tr>
</tbody>
</table>

<br>
<div id="register" class="title">
<h3>设置该批学员开通的课程</h3>
</div>
<div id="waitload"></div>
<div style="height: 469px; width: 787px; overflow-y: auto;"
id="coursenolimit">
<table cellspacing="2" cellpadding="2" class="listtable">
<tbody>
<tr class="line">
<th width="450">课程名</th>
<th>价格</th>
<th>是否已关联</th>
<th>操作</th>
</tr>
<s:iterator value="relatelist">

<tr>
<td><s:property value="cs.cname" /></td>
<td><s:property value="cs.price" /></td>
<%-- <td>未关联</td>
<td>
<a href="s/batchRelate.action?cid=<s:property value="cs.cid"/>&lessonnumber=3&type=1&adminid=1">添加关联</a>
</td>
--%>
<td><s:if test="isRelate==true">
<font color="green">已关联</font>
</s:if> <s:else>未关联</s:else>
</td>
<td><s:if test="isRelate==false">
<a
href="/7e/s/batchUploadRelate.action?cid=<s:property value="cs.cid"/>&lessonnumber=3&adminid=1&type=1">添加关联</a>
</s:if> <%-- <s:elseif test="isRootCourse==false">isRootCourse--<s:property value="isRootCourse"/></s:elseif> --%>


<s:else>
<a
href="/7e/s/batchUploadCloseRelate.action?cid=<s:property value="cs.cid"/>&uid=<s:property value="uid"/>&type=1">
关闭</a>
</s:else>
</td>
<%--
<td><s:if test="isRelate==true">已关联</s:if> <s:else>未关联</s:else>

</td>
<td><s:if test="isRelate==false">
<a
href="/7e/s/batchRelateCourse.action?cid=<s:property value="cs.cid"/>&type=1">添加关联</a>
</s:if> <s:else>
<a
href="/7e/s/closeRelateCourse.action?cid=<s:property value="cs.cid"/>&type=1">关闭</a>
</s:else>
</td> --%>
</tr>
</s:iterator>
</tbody>
</table>
</div>
</div>

<div class="footactions">
<input type="submit" onclick="return btnSubmit_onclick();" class="submit" value="提交" name="batchuploadsubmit">
</div>
</s:form>
</div>
</div>
<s:include value="../../../inc/sides.jsp"></s:include>
</body>
<s:debug></s:debug>
</html>
-----------------------------------------------------------------------------------action
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;

import lombok.Data;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.qieast.platform.admincp.service.IStdCourseService;
import com.qieast.platform.model.HomeMember;
@Data
public class StudentUploadAction extends ActionSupport {
private static final long serialVersionUID = 572146812454l ;
private static final int BUFFER_SIZE = 16 * 1024 ;
private File myFile;
private String contentType;
private String fileName ;
private String imageFileName;
private String caption;
private IStdCourseService stdCourseService;
private int cgid;
private int adminid;



public void setMyFileContentType(String contentType) {
this .contentType = contentType;
}

public void setMyFileFileName(String fileName) {
this .fileName = fileName;
}

public void setMyFile(File myFile) {
this .myFile = myFile;
}

public String getImageFileName() {
return imageFileName;
}

public String getCaption() {
return caption;
}

public void setCaption(String caption) {
this .caption = caption;
}

private static void copy(File src, File dst) {
try {
InputStream in = null ;
OutputStream out = null ;
try {
in = new BufferedInputStream( new FileInputStream(src), BUFFER_SIZE);
out = new BufferedOutputStream( new FileOutputStream(dst), BUFFER_SIZE);
byte [] buffer = new byte [BUFFER_SIZE];

for (int byteRead = 0; (byteRead = in.read(buffer)) > 0; )
{
out.write(buffer, 0, byteRead);
}
} finally {
if ( null != in) {
in.close();
}
if ( null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

private static String getExtention(String fileName) {
return fileName;
}

@Override
public String execute(){

imageFileName = getExtention(fileName);
File imageFile = new File(ServletActionContext.getServletContext().getRealPath( "/uploadfiles" ) + "/" + imageFileName);
copy(myFile, imageFile);
if(check(myFile).equals("error")){
return INPUT;
}else if(write(myFile).equals("error")){
return INPUT;
}else
return SUCCESS;
}

private String check(File myFile2) {
String read;
FileReader fileread;
BufferedReader bufread;
String[] temp = null;
try {
fileread = new FileReader(myFile2);
bufread = new BufferedReader(fileread);
try {
while ((read = bufread.readLine()) != null) {
if(!read.contains(",")){
continue;
}else{
temp = read.split(",");
if(temp.length>2){
return "error";
}
}
}
} catch (IOException e) {
e.printStackTrace();
return "error";
}
} catch (FileNotFoundException e) {
e.printStackTrace();
return "error";
}
return "success";
}

private String write(File myFile2) {
String read;
FileReader fileread;
BufferedReader bufread;
HomeMember homeMember = null;
String[] temp = null;
try {
fileread = new FileReader(myFile2);
bufread = new BufferedReader(fileread);
try {
while ((read = bufread.readLine()) != null) {
if(!read.contains(",")){
continue;
}else{
homeMember = new HomeMember();


temp = read.split(",");
int stdId= stdCourseService.findMaxUid();
homeMember.setUid(stdId);
System.out.println("temp[0].trim():"+temp[0].trim());
homeMember.setUsername(temp[0].trim());
homeMember.setRealname(temp[0].trim());
homeMember.setPassword(temp[1].trim());
Date time = new Date();
long regdate = (long) time.getTime();
homeMember.setRegdate(regdate);

System.out.println(homeMember);
stdCourseService.batchAddStudents(stdId, homeMember, adminid);
}
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return "success";
}
}
-----------------------------------------------------------------------------------web.xml
<!--FCK编辑器-->
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<!-- 此为文件浏览路径 -->
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>SimpleUploader</servlet-name>
<servlet-class>com.fredck.FCKeditor.uploader.SimpleUploaderServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<!-- 此为文件上传路径,需要在WebRoot 目录下新建 UserFiles 文件夹 -->
<!-- 根据文件的类型还需要新建相关的文件夹 Image、Flash -->
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!-- 此参数为是否开启上传功能 -->
<param-name>enabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsFile</param-name>
<param-value></param-value>
</init-param>
<init-param>
<!-- 此参数为文件过滤,以下的文件类型都不可以上传 -->
<param-name>DeniedExtensionsFile</param-name>
<param-value>php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi</param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsImage</param-name>
<param-value>jpg|gif|jpeg|png|bmp</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsImage</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsFlash</param-name>
<param-value>swf|fla</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFlash</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>SimpleUploader</servlet-name>
<url-pattern>/FCKeditor/editor/filemanager/upload/simpleuploader</url-pattern>
</servlet-mapping>
<!--end-->


内容概要:本文围绕EKF SLAM(扩展卡尔曼滤波同步定位与地图构建)的性能展开多项对比实验研究,重点分析在稀疏与稠密landmark环境下、预测与更新步骤同时进行与非同时进行的情况下的系统性能差异,并进一步探讨EKF SLAM在有色噪声干扰下的鲁棒性表现。实验考虑了不确定性因素的影响,旨在评估不同条件下算法的定位精度与地图构建质量,为实际应用中EKF SLAM的优化提供依据。文档还提及多智能体系统在遭受DoS攻击下的弹性控制研究,但核心内容聚焦于SLAM算法的性能测试与分析。; 适合人群:具备一定机器人学、状态估计或自动驾驶基础知识的科研人员及工程技术人员,尤其是从事SLAM算法研究或应用开发的硕士、博士研究生和相关领域研发人员。; 使用场景及目标:①用于比较EKF SLAM在不同landmark密度下的性能表现;②分析预测与更新机制同步与否对滤波器稳定性与精度的影响;③评估系统在有色噪声等非理想观测条件下的适应能力,提升实际部署中的可靠性。; 阅读建议:建议结合MATLAB仿真代码进行实验复现,重点关注状态协方差传播、观测更新频率与噪声模型设置等关键环节,深入理解EKF SLAM在复杂环境下的行为特性。稀疏 landmark 与稠密 landmark 下 EKF SLAM 性能对比实验,预测更新同时进行与非同时进行对比 EKF SLAM 性能对比实验,EKF SLAM 在有色噪声下性能实验
内容概要:本文围绕“基于主从博弈的售电商多元零售套餐设计与多级市场购电策略”展开,结合Matlab代码实现,提出了一种适用于电力市场化环境下的售电商优化决策模型。该模型采用主从博弈(Stackelberg Game)理论构建售电商与用户之间的互动关系,售电商作为领导者制定电价套餐策略,用户作为跟随者响应电价并调整用电行为。同时,模型综合考虑售电商在多级电力市场(如日前市场、实时市场)中的【顶级EI复现】基于主从博弈的售电商多元零售套餐设计与多级市场购电策略(Matlab代码实现)购电组合优化,兼顾成本最小化与收益最大化,并引入不确定性因素(如负荷波动、可再生能源出力变化)进行鲁棒或随机优化处理。文中提供了完整的Matlab仿真代码,涵盖博弈建模、优化求解(可能结合YALMIP+CPLEX/Gurobi等工具)、结果可视化等环节,具有较强的可复现性和工程应用价值。; 适合人群:具备一定电力系统基础知识、博弈论初步认知和Matlab编程能力的研究生、科研人员及电力市场从业人员,尤其适合从事电力市场运营、需求响应、售电策略研究的相关人员。; 使用场景及目标:① 掌握主从博弈在电力市场中的建模方法;② 学习售电商如何设计差异化零售套餐以引导用户用电行为;③ 实现多级市场购电成本与风险的协同优化;④ 借助Matlab代码快速复现顶级EI期刊论文成果,支撑科研项目或实际系统开发。; 阅读建议:建议读者结合提供的网盘资源下载完整代码与案例数据,按照文档目录顺序逐步学习,重点关注博弈模型的数学表达与Matlab实现逻辑,同时尝试对目标函数或约束条件进行扩展改进,以深化理解并提升科研创新能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值