jbos + struts1 + jsp 上传下载

这是一个用于项目信息模块的内容上传功能实现,主要涉及Struts框架、文件上传处理及数据库操作。

import java.io.File;

import java.io.FileOutputStream;

import java.io.OutputStream;

 

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

import org.apache.log4j.Logger;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.upload.FormFile;

 

import com.hymake.wygl.shared.GetBusinessHome;

import com.hymake.wygl.shared.ShareModel;

import com.hymake.wygl.shared.business.XmxxBusiness;

import com.hymake.wygl.shared.business.XmxxBusinessHome;

 

/**

 * @author Jan 14, 2011 项目信息模块内容 上传 临时管理规约 附件(word) <br>

 */

public class DoUploadItemAttachAction extends Action {

     File fileContent;

static Logger logger = Logger.getLogger(ShareModel.class.getName());

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception {

ItemAttachForm itemAttachForm = new ItemAttachForm();

itemAttachForm = (ItemAttachForm) form;

request.setAttribute("entId", itemAttachForm.getItem_id());

request.setAttribute("type", itemAttachForm.getType());

System.out.println("读取文件的URL: "+itemAttachForm.getFilePath());

System.out.println("服务器提交URL: "+request.getServletPath());

System.out.println("项目工程Name: "+request.getContextPath());

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

System.out.println("网络地址:"+basePath);

int MAX_FILE_SIZE =1024 * 1024 * 10;

XmxxBusinessHome xmxxBusinessHome;

XmxxBusiness xmxxBusiness;

OutputStream  fos = null;

try {

FormFile formFile=itemAttachForm.getFileContent();

if(formFile.getFileSize() > MAX_FILE_SIZE){

request.setAttribute("err", "err");

return mapping.findForward("success");

}else{

if(formFile != null){

String dir = request.getSession(true).getServletContext().getRealPath("\\upload");

String dirs[] = dir.split("\\\\");

//文件存放的路径

String filePaht = dirs[0]+"/"+dirs[1]+"/"+dirs[2]+request.getContextPath()+"/"+itemAttachForm.getItem_id()+"/" ;

System.out.println("文件存放的地址:"+filePaht);

File f = new File(filePaht);

if(!f.exists()){

f.mkdirs();

System.out.println("文件存放的目录:"+filePaht+"创建成功!");

}

//去掉文件名的空格

String fileName = formFile.getFileName().trim().replaceAll(" ", "");

//去掉文件名存在的&字符,防止传参数出现错误

fileName = fileName.replaceAll("&", "");

fos = new FileOutputStream(filePaht+fileName);

fos.write(formFile.getFileData(),0,formFile.getFileSize());

fos.flush();

//开启连接

GetBusinessHome getBusinessHome = new GetBusinessHome();

xmxxBusinessHome = getBusinessHome.getXmxxBusinessHome();

xmxxBusiness = xmxxBusinessHome.create();

itemAttachForm.setFileName(fileName);

String sqlPath = dirs[2]+request.getContextPath()+"/"+itemAttachForm.getItem_id()+"/" +fileName;

itemAttachForm.setFilePath(sqlPath);

//保存相应的信息到数据苦中

xmxxBusiness.getDoUpload(itemAttachForm);

}

}

} catch (RuntimeException e) {

e.printStackTrace();

}catch(Exception e){

e.printStackTrace();

}finally{

if(fos != null){

fos.close();

}

}

return mapping.findForward("success");

}

}

-----------jsp  上传查看的jsp --------
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page
import="java.io.*,java.util.*,javax.servlet.http.*,javax.servlet.*"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ page
import="java.sql.*,javax.naming.InitialContext,javax.sql.*,com.hymake.wygl.shared.DataModule.ItemAttachBean"%>
<%
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>上传临时管理规约</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 href="ent/main/inc/style.css" rel="stylesheet" type="text/css"> -->
</head>
<%
  request.setCharacterEncoding("gbk");
String entId = null;
String type = null;
if(request.getParameter("type") != null && request.getParameter("type").trim() !=""){
type = request.getParameter("type");
}else if(request.getAttribute("type") != null){
type = request.getAttribute("type").toString();
}
if (request.getParameter("entId") != null) {
entId = new String(request.getParameter("entId").getBytes("iso-8859-1"),"GBK").trim();
}else if (request.getAttribute("entId") != null) {
entId = request.getAttribute("entId").toString();
}
  %>
<body>
<div>
<label style="font: 15px">项目编号为:<%=entId%></label><br>
<label style="color: red; font: 13 px">
注意:为了保证信息的完整,上传的 <B>word</B> 文件名不能包含有
<B>&</B>符号!
</label>
</div>
<hr>
<%
if(request.getAttribute("err")!= null && request.getAttribute("err").equals("err")){
%>
<div>
<label style="color: red; font: 13 px;">
<B>上传失败:上传的文件超过10M,请分成多个文件提交上传。</B>
</label>
</div>
<%
}
%>
<form action="<%=path%>/doUploadItemAttach.do" method="post"
enctype="multipart/form-data" onsubmit="return onSubmiFileContent();">
<input type="hidden" name="item_id" value="<%=entId%>">
<input type="hidden" name="type" value="<%=type%>">
<input type="hidden" name="filePath" id="filePathId">
<table width="100%" border="0" cellpadding="0" cellspacing="0"
bgcolor="#FFFFFF">
<tr>
<td valign="top">
<table width="100%" border="0" cellpadding="4" cellspacing="0"
class="indiv">
<tr align="justify">
<td  align="left" style=" FONT-SIZE: 9pt;">
临时管理规约(word):
</td>
<td>
<input type="file" name="fileContent" id="fileContentid" onchange="fileURL();" onclick="fileURL();" size="15">
<input type="submit" value=" 上传附件" size="20" style=" FONT-SIZE: 9pt;">
<input type="button" value="关闭" onclick="window.close();" style=" FONT-SIZE: 9pt;">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>

<table width="100%" border="0" cellpadding="5" cellspacing="0"
bgcolor="#FFFFFF">
<%
  DataSource ds = null;
    java.sql.Connection con=null;
 Statement stmt = null;
 String photoName ="";
 String sql = "";
  try{
  String dir = request.getSession(true).getServletContext().getRealPath("\\upload");
String dirs[] = dir.split("\\\\");
//文件存放的路径
String filePaht = dirs[0]+"/"+dirs[1]+"/" ;
    InitialContext initCtx = new InitialContext();
    ds = (DataSource)initCtx.lookup("java:/MSSQLDS");
    con=ds.getConnection();
sql = "SELECT * FROM item_attach where item_id='"+entId+"' and type='"+type+"'";
System.out.print(sql);
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
     ResultSet rs = stmt.executeQuery(sql);
  while(rs.next()){
  %>
<tr>
<td>
<form name="goodform"
action="<%=path%>/ent/main/upload_attachDelete.jsp?entId=<%=entId%>&fileName=<%=new String(rs.getString("fileName").getBytes(),"gbk") %>&type=<%=type%>" method="post"
>
<table class="indiv4">
<tr>
<td style=" FONT-SIZE: 9pt;">
<img alt="点击连接,单份下载浏览" src="<%=path%>/ent/main/images/icon02c.gif" width="70"
height="70" />
<input type="hidden" name="item_id" value="<%=entId%>">
<input type="hidden" name="type" value="<%=type%>">
<input type="hidden" name="fileName" value="<%=new String(rs.getString("fileName").getBytes(),"gbk") %>">
</td>
<td align="center" style=" FONT-SIZE: 9pt;">
<a href="<%=path%>/uploadItemAttachFile.do?item_id=<%=entId%>&fileName=<%=new String(rs.getString("fileName").getBytes(),"gbk") %>&type=<%=type%>">
<%=new String(rs.getString("fileName").getBytes(),"gbk") %>
</a>
</td>
<td align="right" style=" FONT-SIZE: 9pt;"><input type="submit" value=" 删 除 "></td>
</tr>
</table>
</form>
</td>
</tr>
<%
   }
} catch (Exception e){
     e.printStackTrace();
   }
   finally {
  try{
              stmt.close();
            con.close();
 }catch(Exception e){
 System.out.print("不能关闭数据库连接" + e);
 }
        }       
%>
</table>

</body>
<script type="text/javascript">
   function onSubmiFileContent(){
var fileContentValue = document.getElementById("fileContentid").value;
if(fileContentValue == null || fileContentValue ==""){
alert("请浏览选择要上传的附件(word)!");
return false;
}
return true;
}
function proveDel(){
if(!confirm("删除将要从新上传,是否确定删除!")){
return false;
}
return true;
}
function fileURL(){
document.getElementById("filePathId").value = document.getElementById("fileContentid").value;
}
  </script>
</html>

-------- 下载的 action-------

package com.hymake.wygl.ent.xmxx;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.hymake.wygl.shared.DataModule.ItemAttachBean;

/**
 * @author jianght
 * Jan 20, 2011
 * 读取附件信息
 * <br>
 */
public class UploadItemAttachFileAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
InputStream  infile = null;
try {
ItemAttachForm itemAttachForm = new ItemAttachForm();
ItemAttachBean itemAttachBean = new ItemAttachBean();
itemAttachForm = (ItemAttachForm) form;
request.setAttribute("entId", itemAttachForm.getItem_id());
request.setAttribute("type", itemAttachForm.getType());
String fileName = new String (request.getParameter("fileName").getBytes("iso-8859-1"),"gbk");
itemAttachForm.setFileName(fileName);
PropertyUtils.copyProperties(itemAttachBean,form);
String filePaht =null;
filePaht = itemAttachBean.getDoUploadAttachFile();
String dir =  request.getSession(true).getServletContext().getRealPath("\\upload");
String dirs[] = dir.split("\\\\");
filePaht = dirs[0]+"/"+dirs[1]+"/" + filePaht;
 
File file=new File(filePaht);
if(!file.exists()){
System.out.println(filePaht + "  文件不存在");
return null;
}
System.out.println("服务器存放的地址: "+ filePaht);
infile = new BufferedInputStream( new FileInputStream(file));
int srcFileSize  = infile.available();
 
byte[] b = new byte[srcFileSize];
response.setContentType("application/msword");
fileName = new String(fileName.getBytes("gb2312"),"ISO_8859_1");
response.setHeader("content-disposition", "attachment;filename="+fileName);
response.setCharacterEncoding("gb2312");
while(infile.read(b) != -1){
response.getOutputStream().write(b);
}

} catch (RuntimeException e) {
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
            if ( null != infile)  {
             infile.close();
            } 
        } 
return mapping.findForward("success");
}
}
----------Bean 和Form

private String item_id; //项目编号
private String type; //类型
private String fileName; //文件名
private FormFile fileContent; //文件内容
private String filePath; //文件路径


本项目采用C++编程语言结合ROS框架构建了完整的双机械臂控制系统,实现了Gazebo仿真环境下的协同运动模拟,并完成了两台实体UR10工业机器人的联动控制。该毕业设计在答辩环节获得98分的优异成绩,所有程序代码均通过系统性调试验证,保证可直接部署运行。 系统架构包含三个核心模块:基于ROS通信架构的双臂协调控制器、Gazebo物理引擎下的动力学仿真环境、以及真实UR10机器人的硬件接口层。在仿真验证阶段,开发了双臂碰撞检测算法和轨迹规划模块,通过ROS控制包实现了末端执行器的同步轨迹跟踪。硬件集成方面,建立了基于TCP/IP协议的实时通信链路,解决了双机数据同步和运动指令分发等关键技术问题。 本资源适用于自动化、机械电子、人工智能等专业方向的课程实践,可作为高年级课程设计、毕业课题的重要参考案例。系统采用模块化设计理念,控制核心与硬件接口分离架构便于功能扩展,具备工程实践能力的学习者可在现有框架基础上进行二次开发,例如集成视觉感知模块或优化运动规划算法。 项目文档详细记录了环境配置流程、参数调试方法和实验验证数据,特别说明了双机协同作业时的时序同步解决方案。所有功能模块均提供完整的API接口说明,便于使用者快速理解系统架构并进行定制化修改。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文围绕基于非支配排序的蜣螂优化算法(NSDBO)在微电网多目标优化调度中的应用展开研究,提出了一种改进的智能优化算法以解决微电网系统中经济性、环保性和能源效率等多重目标之间的权衡问题。通过引入非支配排序机制,NSDBO能够有效处理多目标优化中的帕累托前沿搜索,提升解的多样性和收敛性,并结合Matlab代码实现仿真验证,展示了该算法在微电网调度中的优越性能和实际可行性。研究涵盖了微电网典型结构建模、目标函数构建及约束条件处理,实现了对风、光、储能及传统机组的协同优化调度。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事微电网、智能优化算法应用的工程技术人员;熟悉优化算法与能源系统调度的高年级本科生亦可参考。; 使用场景及目标:①应用于微电网多目标优化调度问题的研究与仿真,如成本最小化、碳排放最低与供电可靠性最高之间的平衡;②为新型智能优化算法(如蜣螂优化算法及其改进版本)的设计与验证提供实践案例,推动其在能源系统中的推广应用;③服务于学术论文复现、课题研究或毕业设计中的算法对比与性能测试。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注NSDBO算法的核心实现步骤与微电网模型的构建逻辑,同时可对比其他多目标算法(如NSGA-II、MOPSO)以深入理解其优势与局限,进一步开展算法改进或应用场景拓展。
内容概要:本文详细介绍了使用ENVI与SARscape软件进行DInSAR(差分干涉合成孔径雷达)技术处理的完整流程,涵盖从数据导入、预处理、干涉图生成、相位滤波与相干性分析、相位解缠、轨道精炼与重去平,到最终相位转形变及结果可视化在内的全部关键步骤。文中以Sentinel-1数据为例,系统阐述了各环节的操作方法与参数设置,特别强调了DEM的获取与处理、基线估算、自适应滤波算法选择、解缠算法优化及轨道精炼中GCP点的应用,确保最终获得高精度的地表形变信息。同时提供了常见问题的解决方案与实用技巧,增强了流程的可操作性和可靠性。; 适合人群:具备遥感与GIS基础知识,熟悉ENVI/SARscape软件操作,从事地质灾害监测、地表形变分析等相关领域的科研人员与技术人员;适合研究生及以上学历或具有相关项目经验的专业人员; 使用场景及目标:①掌握DInSAR技术全流程处理方法,用于地表沉降、地震形变、滑坡等地质灾害监测;②提升对InSAR数据处理中关键技术环节(如相位解缠、轨道精炼)的理解与实操能力;③实现高精度形变图的生成与Google Earth可视化表达; 阅读建议:建议结合实际数据边学边练,重点关注各步骤间的逻辑衔接与参数设置依据,遇到DEM下载失败等问题时可参照文中提供的多种替代方案(如手动下载SRTM切片),并对关键结果(如相干性图、解缠图)进行质量检查以确保处理精度。
此项目旨在实现一个简易而实用的RFID智能门禁控制系统。采用经典的51系列单片机——STC89C52作为核心控制器,集成MFRC522射频识别模块来读取RFID卡片信息。用户界面通过128x64像素的LCD显示屏展示相关信息,同时配备了键盘用于密码的输入、验证及修改。此设计结合了RFID技术的高效率识别与单片机的强大控制能力,适用于学习、教学或小型安防项目。 资源包含 源代码:完整C语言编写的源程序,涵盖了RFID识别、密码验证逻辑、显示控制以及用户交互等功能模块。 原理图:详细展示了整个系统的电路连接,包括单片机、MFRC522模块、LCD12864屏幕、按键等组件的电气连接方式,便于理解和自制。 技术特点 RFID技术应用:通过MFRC522模块实现非接触式身份认证,提升门禁安全性与便捷性。 人机交互界面:利用LCD12864显示屏直观展示状态信息,并通过物理按键进行操作,增加了系统的易用性。 密码安全机制:支持用户密码的设定和更改,增强系统安全性。 51单片机编程:适合初学者和专业人士学习51单片机应用开发,尤其是嵌入式系统与物联网领域的实践。 使用指南 环境搭建:确保你有合适的IDE(如Keil uVision)安装以编译51单片机的C代码。 原理图分析:详细阅读原理图,了解各部件间的连接,这对于正确搭建硬件平台至关重要。 编译与上传:将提供的源代码编译无误后,通过编程器或ISP接口烧录到STC89C52单片机中。 硬件组装:根据原理图搭建电路,确保所有组件正确连接。 测试与调试:完成后进行功能测试,可能需要对代码或硬件做适当调整以达到最佳工作状态。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值