弹出保存路径:
js:
window.open(str,'blank_','scrollbars=no,resizable=no,width=10,height=10,menubar=no');
-------------------------
struts中:
//图片
response.setContentType("image/jpg");
response.setHeader("Content-disposition",
"attachment;filename=\"" + mail.getFileName() + "\";");
BufferedImage image = null;
image=ImageIO.read(in);
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
in.close();
//excel
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition",
"attachment;filename=\"" + mail.getFileName() + "\";");
OutputStream out = response.getOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
int len = 0;
byte[] buf = new byte[1];
while((len = in.read(buf)) != -1)
{
out.write(buf, 0, len);
}
wb.write(out);
out.close();
return null;
---------------------------------------------------------------------------------------
将图片流从数控库取出,显示到JSP
//jpg
HttpServletResponse response = (HttpServletResponse)
ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);
byte[] buf = new byte[1];
response.setContentType("image/jpeg");
OutputStream os=response.getOutputStream();
int len = 0;
while((len = in.read(buf)) != -1)
{
os.write(buf, 0, len);
}
os.close();
in.close();
return null;
---jsp
<s:property value="response.getOutputStream()"/>
//text file
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
mail.setMessageBody(sb.toString());
//jsp
<s:property value="mailVO.messageBody"/>
--------------------------------------------------------------------------------------------------------------------------------
public class Test1
{
public static void main(String[] args)
{
// attachmentEncryption();
attachmentDecryption();
}
public static void attachmentEncryption()
{
InputStream in = null;
byte[] buf = new byte[100];
int len = 0;
BasicBinaryEncryptor encryptor = new BasicBinaryEncryptor();
try
{
in = new FileInputStream(new File("D:\\file.txt"));
encryptor.setPassword("test");
byte[] myEncryptedBinary = encryptor.encrypt(InputStreamToByte(in));
InputStream sbs = new ByteArrayInputStream(myEncryptedBinary);
FileOutputStream os = new FileOutputStream(new File("D:\\temp.txt"));
while((len = sbs.read(buf)) != -1)
{
os.write(buf, 0, len);
}
in.close();
sbs.close();
os.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void attachmentDecryption()
{
InputStream in = null;
FileOutputStream os = null;
byte[] buf = new byte[100];
int len = 0;
BasicBinaryEncryptor encryptor = new BasicBinaryEncryptor();
try
{
in = new FileInputStream(new File("D:\\temp.txt"));
encryptor.setPassword("test");
byte[] binary = encryptor.decrypt(InputStreamToByte(in));
InputStream sbs = new ByteArrayInputStream(binary);
os = new FileOutputStream(new File("D:\\result.txt"));
while((len = sbs.read(buf)) != -1)
{
os.write(buf, 0, len);
}
in.close();
sbs.close();
os.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static byte[] InputStreamToByte(InputStream iStrm) throws IOException
{
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch;
while ((ch = iStrm.read()) != -1)
{
bytestream.write(ch);
}
byte imgdata[]=bytestream.toByteArray();
bytestream.close();
return imgdata;
}
public static void textEncryption()
{
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword("test");
String myEncryptedText = textEncryptor.encrypt("this's a encrypted mail");
System.out.println("encrypted text: "+myEncryptedText);
String plainText = textEncryptor.decrypt(myEncryptedText);
System.out.println("plain text: "+plainText);
}
}
分享到:
相关推荐
这Demo里边有一个1.jsp,它是传一个word文件,然后读取doc里的文字和图片到jsp显示。还有一个html5的画板Demo,可以再jsp里绘画,应该还有其他的比如编辑器的Demo,用了hibernate和struts2,运行tomcat前修改数据库...
JSP strus2实验评价管理系统 是一套完善的WEB设计系统,对理解JSP java 编程开发语言有帮助,系统采用struts2框架 MVC模式进行开发,系统具有完整的源代码和数据库,系统主要采用B/S模式开发。 应用技术:java|jsp+ ...
hibernate和struts存图片到数据库并读取显示在jsp
《JSP网络编程从基础到实践》光盘说明 光盘的实例代码目录中包含了前10章的所有实例的源代码,实例名称及其所处章节如下: 第1章 JSP技术概述 实例1 第一个JSP页面 第3章 Web开发基础 实例2 HTML与JavaScript交互...
15. Struts程序启动时,首先从配置文件struts-config.xml文件中读取相关信息,根据这些信息,控制器可以知道把视图中的请求转发给那个业务逻辑处理。视图组件,控制器,业务逻辑组件之间没有代码的联系。 16. Struts...
《JSP网络编程从基础到实践》 实例1 第一个JSP页面 Web开发基础 实例2 HTML与JavaScript交互示例 JSP语法 实例3 JSP程序的基本结构 实例4 简单数据类型综合应用实例 实例5 包装类综合应用...
JSP网络编程从基础到实践的实例代码 《JSP网络编程从基础到实践》光盘说明 光盘的实例代码目录中包含了前10章的所有实例的源代码,实例名称及其所处章节如下: 第1章 JSP技术概述 实例1 第一个JSP页面 第3章 Web...
Struts的增删改查分页 入门级的经典项目,带数据库的sql数据文件 包含JSTL读取MAP集合 批量删除 还有实现全选,反选, 只是前台的jsp页面未作页面校验,望各位输入到数据库的数据的合法性 保证下载 导入文件和...
《JSP网络编程从基础到实践》光盘说明 光盘的实例代码目录中包含了前10章的所有实例的源代码,实例名称及其所处章节如下: 第1章 JSP技术概述 实例1 第一个JSP页面 第3章 Web开发基础 实例2 HTML与JavaScript交互...
web.xml读取连接数据库的参数,实现代码。
Struts实现的文件上传下载,是保存在服务器上的 不是数据库,希望看清楚再下 省的浪费各位的分,由于时间有限,没有对数据库操作,上传后文件放在服务器里项目的根目录下的upload里,可以新建张表,把文件名称和路径...
全书分4篇,共24章,其中,第1篇为技能学习篇,主要包括Java Web开发环境、JSP语法、JSP内置对象、Java Bean技术、Servlet技术、EL与JSTL标签库、数据库应用开发、初识Struts2基础、揭密Struts2高级技术、Hib锄劬e...
JSP+Servlet+Struts+Hibernate+Spring+Ajax》重点讲解了Struts 2、Speing和HIbernate框架的基础知识和高级技术,如Sruts 2中的*、类型转换、国际化和标签等,HIbe rna{e的会话、0/R映射和事务管理等,Spring中的...
用JSP写的一个完整网站,基于Struts架构,可实现换发功能,预定理发师,拥有后台管理,图像存储与读取于数据库。
JSP+Servlet+Struts+Hibernate+Spring+Ajax》重点讲解了Struts 2、Speing和HIbernate框架的基础知识和高级技术,如Sruts 2中的*、类型转换、国际化和标签等,HIbe rna{e的会话、0/R映射和事务管理等,Spring中的...
数字证书:从文件中读取数字证书,生成文件输入流,输入文件为c:/mycert.cer,获取一个处理X.509证书的证书工厂…… Java+ajax写的登录实例 1个目标文件 内容索引:Java源码,初学实例,ajax,登录 一个Java+ajax写...
Action调用业务逻辑组件处理业务逻辑,Action执行完毕,根据struts.xml中的配置找到对应的返回结果result,并跳转到相应页面。最后返回HTTP响应到客户端浏览器。 5. Hibernate 在持久化操作时的工作步骤 Hibernate...
struts2+spring4.0+hibernate4.0框架,读取数据库并在jsp页面显示
在Struts中应用标签的数据库分页示例(dbpage.jsp),打开方法: http://localhost:8080/pagertaglib/dbPageAction.do?pageSize=5&pager.offset=0&pageNo=1<br>在Struts中应用标签但一次取数据在页面自动分页的示例...
3.在JSP中如何读取客户端的请求,如何访问CGI变量,如何确定某个Jsp文件的真实路径。 4.描述Cookie和Session的作用,区别和各自的应用范围,Session工作原理。 5.列出Jsp中包含外部文件的方式,两者有何区别。 6....