jsp上传图片,并加以显示

上传图片代码如下,首先是页面:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>
<%@ taglib prefix="s" uri="/struts-tags" %>

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

<html>

  <head>

    <base href="<%=basePath%>">
    
    <title>My JSP 'index1.jsp' starting page</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">

	-->

  </head>

  <body>

  这是一个图片上传程序,在上传的时候form必须加上 enctype="multipart/form-data"

  否则则会有报错的情况发生,action类里新建一个demo对象,对应数据库里一条新的记录

  大概方法就是这样,如果有需要的话还可以再扩展,图片上传代码完毕

  <form id="form1" name="form1" action="text.do" method="post" enctype="multipart/form-data">

  	<input type="file" id="userImage" name="userImage">

 	<input type="text" id="mytext" name="mytext">

  <input type="submit" value="确定">

  </form>

    </body>

</html>

 传递至textAction这个类中

我用的是springside的框架,这个框架中的action默认执行的方法是list,其它不变

下边是action类

package com.mytext.action;

import java.awt.image.BufferedImage;

import java.io.ByteArrayInputStream;
import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.io.output.ByteArrayOutputStream;

import org.springframework.beans.factory.annotation.Autowired;

import org.springside.modules.web.struts2.CRUDActionSupport;

import com.mytext.entity.Demo;

import com.mytext.service.DemoServices;

import com.sun.xml.internal.ws.util.ByteArrayBuffer;

@SuppressWarnings("serial")

public class TextAction extends CRUDActionSupport<Demo>{

	@Autowired

	private DemoServices demoServices;
	
	private Demo demo;

	private String mytext;

	private File userImage;

	@Override

	public String delete() throws Exception {

		// TODO Auto-generated method stub

		return null;

	}

	@Override

	public String list() throws Exception {		

	if(userImage==null)

		{
				return "try";
			}

			prepareModel();

		try {

				BufferedImage tt = ImageIO.read(userImage);

				demo.setImage(toByte(tt));

				demo.setName(mytext);

				demoServices.save(demo);




			} catch (Exception e) {

				System.out.println("保存失败");

				return "try";

			}

			return "try";
	
		//demoServices.getAllDemo();	
	}


//转化为流

	private byte[] toByte(BufferedImage image) throws IOException


	{	


		ByteArrayOutputStream cc = new   ByteArrayOutputStream();


			ImageIO.write(image, "jpg", cc);

			return cc.toByteArray();	

	}

	@Override

	protected void prepareModel() throws Exception {

		// TODO Auto-generated method stub

		demo = new Demo();
	}

	@Override

	public String save() throws Exception {

		// TODO Auto-generated method stub

		return null;

	}

	public Demo getModel() {

		// TODO Auto-generated method stub

		return demo;

	}

	public File getUserImg() {

		return userImage;

	}

	public void setUserImg(File userImage) {

		this.userImage = userImage;

	}

	public String getMytext() {

		return mytext;

	}

	public void setMytext(String mytext) {

		this.mytext = mytext;

	}

	public File getUserImage() {

		return userImage;
	}

	public void setUserImage(File userImage) {

		this.userImage = userImage;

	}
}


 文中加红的为保存方法,是springside独有的一个东西,不必深究,可跟据自己的框架来保存对象至数据库中

下边是我数据库的实体类

package com.mytext.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Demo entity.
 * 
 * @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "demo")
public class Demo extends IdEntity implements java.io.Serializable




{

	private String name;
	private byte[] image;
	private String shouming;
	public Demo() {
	}
	public Demo(String name, byte[] image) {
		this.name = name;
		this.image = image;
	}

	@Column(name = "name", length = 15)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "image")
	public byte[] getImage() {
		return this.image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}
	@Column(name="shouming", length = 225)
	public String getShouming() {
		return shouming;
	}
	public void setShouming(String shouming) {
		this.shouming = shouming;
	}

}

 继承了一个共用的类,用于id主键生成

package com.mytext.entity;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
//所有实体类的基类,实现id的自增长
@MappedSuperclass
public class IdEntity {
	private Long id;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
}

 我用的是mysql数据库,测试己成功,action方法中继承的是springside框架中的action类,不用这个框架的不必深究,

 

 

以下是在jsp页面中读出图片的方法

 

先是jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%@ taglib prefix="s" uri="/struts-tags"  %>




     <!--  注意标签库的异入>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>jquery编辑器实例</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">
	-->
	<link rel="stylesheet" href="${ctx }/edit/common.css" type="text/css" media="screen" />
	<script type="text/javascript" src="${ctx }/edit/jquery/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="${ctx }/edit/xheditor.js"></script>
  </head>
  <body>
  <!--  jquery的编辑器试验己成功,能够成功写入数据库,能够成功在页面上显示出来 -->
  一般模式的edit
  <form method="post" action="edit.do">
	<h3>xhEditor demo1 : 默认模式</h3>
	xheditor(默认完全):<br />
	<textarea id="elm1" name="elm1" class="xheditor" rows="12" cols="80" style="width: 80%">
    <p>请输入信息</p>
    </textarea>
    <br>
     <input type="submit" value="试验中的jquery编辑器">
   </form>
   <!-- 从数据库里边读出一个图片 至此,图片上传和显示制做完毕-->
   开始从数据库里边读出来一个图片<br>
   <img src="<s:url action="edit!getUserImgFromByte.do">
   <s:param name="id" value="5"></s:param>
   </s:url>" height="300px" width="300px"> 








  </body>
</html>
 

红色部分为显示图片,可人为控制图看大小,上边的是一个类似于fck的jquery编辑器

 

action方法

package com.mytext.action;

import java.io.IOException;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.web.struts2.CRUDActionSupport;
import org.springside.modules.web.struts2.Struts2Utils;

import com.mytext.entity.Demo;
import com.mytext.service.DemoServices;

public class EditAction extends CRUDActionSupport<Demo>{

	/**
	 * 
	 */
	@Autowired
	private DemoServices demoSdrvices;
	
	private Long id;
	private String elm1;
	private Demo demo;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws Exception {
		id=1L;
		getModel();
		demo.setShouming(elm1);
		demoSdrvices.save(demo);
		return "showedit";
	}

	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public Demo getModel() {
		if(id==null)
		{
			demo=new Demo();
		}
		else
		{
			demo = demoSdrvices.get(id);
		}
		return demo;
	}

	public String getElm1() {
		return elm1;
	}

	public void setElm1(String elm1) {
		this.elm1 = elm1;
	}

	public Demo getDemo() {
		return demo;
	}

	public void setDemo(Demo demo) {
		this.demo = demo;
	}
	public String getUserImgFromByte() throws Exception {
		getModel();
		HttpServletResponse response = Struts2Utils.getResponse();
		ServletOutputStream out = null;
		try {
			response.setContentType("image/jpeg");
			out = response.getOutputStream();
			out.write(demo.getImage());
			out.flush();
		} catch (Exception e) {
		} finally {
			try {
				if (null != out)
					out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}





}
 

红色部分为从数据库读图片代码

转载使用请注明出处!写的时候不知道,后来才发现代码内部不能加红!!!

真屎!

读本人博客代码如有任何疑问或代码不能执行,请速联系本人

zhang7789@yahoo.com.cn

 

 

JSP中图片的上传与显示方法实例详解 主要介绍了JSP中图片的上传与显示方法,以实例形式较为详细的分析了数据库的创建、图片存储、图片文件的传输及页面显示等相关实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下 立即下载

相关推荐

jsp中实现上传图片即时显示效果功能

上传图片时即时显示图片效果,这在项目开发中时很常见的一项功能,接下来介绍此功能的实现过程,有需要的朋友可以参考下

JSP关于图片的上传与显示

SmartUpload

ifyouwjk的博客 3818

INCA_ProF脚本教程

一、首先INCA软件是当前主流标定开发软件之一,尤其在动力系统控制器的标定中应用非常广泛;与此同时ProF编程脚本是INCA软件提供各种实用功能之一,使用者可根据需求编写ProF脚本语言对ECU闪存编程等各种自定义操作。 二、然而ProF脚本语言在ETAS的官网或其他网络上并没有专门的使用教程,通常只有ETAS技术支持人员提供的ProF Documentation文档或少量可参考的Demo案例,然而ProF Documentation文档仅涉及ProF语言的函数的操作说明,没有从全局的框架上介绍Pro

weixin_29389627的博客 1万+

采用jsp+servlet+Javabean实现图片上传和展示

sp+servlet+Javabean实现图片上传和展示

weixin_44899752的博客 3507

别再只看OPLS-DA得分图了!R2Y和Q2Y到底怎么看?一次讲透代谢组学模型验证

刚接触代谢组学数据分析的研究者,往往会被OPLS-DA得分图中清晰的分组效果所吸引,迫不及待地认为发现了显著差异。这种"看图说话"的冲动,恰恰是许多科研新手在审稿或项目汇报中遭遇质疑的根源。真正专业的分析,需要穿透图形表象,深入理解模型验证指标R2Y和Q2Y背后的统计学意义。

weixin_28683391的博客 188

边缘设备选型指南:从数据采集到AI推理,工业物联网硬件如何匹配你的需求?

本文提供了一份全面的工业物联网边缘设备选型指南,系统性地阐述了如何根据数据采集、协议兼容性、边缘AI推理算力及环境适应性等核心需求匹配硬件。文章深入剖析了从CPU/GPU/NPU选择到MQTT、Sparkplug B等工业协议支持的实战考量,并强调了软件生态与全生命周期成本的重要性,旨在帮助项目负责人在复杂场景中做出明智决策。

weixin_29168813的博客 94

jsp 上传图片并显示

Apache commons-fileupload是一个很好的文件上传工具,最近使用commons-fileupload实现了图片的上传及显示,可将图片保存在指定的文件夹中,也可以将图片存放在数据库,并支持四种常用的图片格式:jpg,png,gif,bmp。   首先,跟上传一般文件一样,需要写一个servlet来处理上传的文件,你可以修改保存路径或选择将图片保存在数据库中,只需要做简单的修改就...

chenzhanhai的专栏 7697

海康VisionMaster零代码开发实战:从PLC工程师到视觉专家的捷径

本文为PLC工程师提供了利用海康VisionMaster视觉平台实现零代码视觉开发的实战指南。文章详细阐述了如何通过图形化流程设计替代传统编程,快速搭建视觉检测应用,并实现与PLC的无缝通讯,是工程师从设备控制迈向视觉系统集成的有效捷径。

weixin_29201859的博客 298

struts2上传图片,并显示在 jsp 上

这是目录结构,我用的是eclipse,这几天刚学了一点struts, 找了些资料,测试一下能上传成功! ------------------------------------------------------------------------------------------------------------ 1.  我要传到 工程目录 webContent 下 的 “ pict

兜里揣板砖 的专栏 3031

告别数据丢失焦虑:用Python手把手实现Reed-Solomon码(附完整代码)

本文详细介绍了如何使用Python实现Reed-Solomon纠错码(RS码),帮助开发者有效防止数据丢失。通过基础编解码实战、文件保护方案和高级性能优化技巧,读者可以轻松掌握这一前向纠错技术,应用于物联网、文件存储和网络传输等场景,提升数据可靠性。

weixin_42527160的博客 229

西门子S7-200 SMART PLC高速计数器与增量式编码器实战配置指南

在工业自动化控制系统中,传感器是将物理量转换为电信号的关键组件,其中编码器作为核心的位置与速度检测元件,其工作原理基于光电或磁电效应,将机械位移转换为脉冲序列。增量式编码器通过输出相位差90度的A/B两相脉冲,不仅能实现精确的位移测量,还能通过相位关系自动判别运动方向,并通过倍频技术提升分辨率。其技术价值在于为PLC等控制器提供了实时、高精度的位置反馈,是实现闭环控制、提升系统精度与可靠性的基础。在包装机械、物料输送、绕线设备等应用场景中,编码器与PLC高速计数器的协同工作是实现精确定位、定长切割与速度控制

weixin_29178069的博客 406

java中图片上传并在jsp页面显示

本文将阐述怎么使用commons-fileupload将图片上传至mysql数据库,并利用java servlet将其在浏览器中显示 出来。 前提条件: 正确安装了mysql,tomcat,并下载了commons-fileupload-1.0.jar。 1,前台页面 ---test_upload.htm--- 上传测试 your nam

抬头30°的微笑的专栏 5962

【并发编程五】c++进程通信——共享内存(shared memmory)

现代操作系统,对于内存管理,采⽤的是虚拟内存技术,也就是每个进程都有⾃⼰独⽴的虚拟内存空间,不同进程的虚拟内存映射到不同的物理内存中。所以,即使进程 A中 和 进程 B中 的虚拟地址是⼀样的,其实访问的是不同的物理内存地址,对于数据的增删查改互不影响。这样这个进程写⼊的东⻄,另外⼀个进程⻢上就能看到了,都不需要拷⻉来拷⻉去,传来传去,⼤⼤提⾼了进程间通信的速度。⽤了共享内存通信⽅式,带来新的问题,那就是如果多个进程同时修改同⼀个共享内存,很有可能就冲突了。那共享内存的⽅式,就很好的解决了这⼀问题。

junxuezheng的博客 1万+

JSP 上传图片并显示、按钮返回,返回前一页

jsp上传图片并显示,暂无后端接口交互

Be_insighted的博客 833

2023年全国职业院校技能大赛 网络系统管理服务模块 Linux部分讲解

网络系统管理,Linux,服务部署,Chinaskills,2023国赛

weixin_62926639的博客 1551

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

button上传替换file上传按钮,并显示图片缩略图,纯jsp操作

1、jsp代码 &lt;div class="inputBox"&gt; &lt;span id="tu" &lt;c:if test="${pd == null || pd.CACHET == '' || pd.CACHET == null}"&gt;style="display: none;"&lt;/c:if&am

weixin_34354173的博客 700

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

java上传显示图片_jsp怎么上传显示图片

jsp上传显示图片的方法:首先创建上传JSP页面;然后创建上传图片后台处理业务“upload.jsp”;最后使用JS完成交互。之前做过一个项目,有一个功能是图片上传并且展示图片,尝试过其他的方法,但会有一个问题,那就是在IE8上图片并不能下常展示,所以便用以下方法来上传图片,很好的解决了此问题,步骤如下:1.上传图片页面index.jspString path = request.getConte...

weixin_35382961的博客 1616

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jsp mysql图片上传_JSP+java上传图片到服务器,并将地址保存至MYSQL + JSP网页显示服务器的图片...

这两天遇到个需求——用户头像修改功能。查了好多资料,不是代码不全,就是某些高端框架,卡了好久,今已实现,分享给大家,如果有更好的方法,非常感谢可以在下方评论区写出一、整体项目架构二、web.xml配置文件UploadServletUploadServletcom.runoob.test.UploadServletUploadServlet/lianxi/UploadServletgetImgget...

weixin_39972151的博客 412

如何通过jsp、html上传图片到数据库,及如何从数据库中取出blob类型并显示到页面中

1、通过jsp、html上传图片到数据库 先在addProduct.jsp前面加上文件类型控件, 页面上显示 然后选择文件,提交给后端接口的doPost或service方法,获得输入流: InputStream inputStream=null; Part filePart = req.getPart("picture"); if(filePart!=null) { System.out.println("file name :"+filePart.

zds18205657013的博客 2676

java jsp filename filepath 图片上传_JSP+java上传图片到服务器,并将地址保存至MYSQL + JSP网页显示服务器的图片...

这两天遇到个需求——用户头像修改功能。查了好多资料,不是代码不全,就是某些高端框架,卡了好久,今已实现,分享给大家,如果有更好的方法,非常感谢可以在下方评论区写出一、整体项目架构 二、web.xml配置文件UploadServletUploadServletcom.runoob.test.UploadServletUploadServlet/lianxi/UploadServletgetImgge...

weixin_42137022的博客 297

html单选框判断以及图片上传并显示 jsp

通过js去判断做的题目是否正确 做一个考试网站时,通常需要去判断题目是否正确。 jsp页面代码 <div> <c:forEach var="exam" items="${examList}"> <!--题目--> ${exam.question}(选择题) <div> <input ...

NOT NULL 347

JSP+java上传图片到服务器,并将地址保存至MYSQL + JSP网页显示服务器的图片

这两天遇到个需求——用户头像修改功能。 查了好多资料,不是代码不全,就是某些高端框架,卡了好久,今已实现,分享给大家,如果有更好的方法,非常感谢可以在下方评论区写出 一、整体项目架构 二、web.xml配置文件 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:/...

weixin_30377461的博客 386

基于jsp+ServletFileUpload+mysql,上传图片存储虚拟地址到数据库并显示

1.数据库表结构: 图片在数据库存储方式为虚拟路径 ! 2.依赖包:commons-fileupload-1.3.2.jar和commons-io-2.5.jar 下载地址:(根据自己项目jdk版本来下) http://commons.apache.org/proper/commons-fileupload/ http://commons.apache.org/proper/comm...

剑指长空 5413

JSP上传图片(或文件)并显示缩略图(附带解决IE7中无法显示缩略图)

//第一个页面uploadImg.jsp//上传使用第三方的包:JspSmartUpload,可以在csdn上下载到,需要的话可以联系我patriot074@163.com@ page language="java" import="java.util.*" pageEncoding="gb2312"%> request.setCharacterEncoding("gb2312"); //

4618

servlet上传图片到项目文件下并将商品信息和图片添加至数据库,jsp显示出数据库的图片以及商品信息(记录自己的项目,代码可能不全,仅供参考)

一、上传图片到项目文件并添加至数据库中 JDBCTest.java 连接数据库 package petTest.dao; import java.sql.*; import petTest.bean.*; import java.sql.Connection; public class JDBCTest { private static String url="jdbc:mysql://localhost:3306/pethospitalmanager?useUnicode=true&cha

World peace的博客 945
上一篇: 用javamail来发邮件
下一篇: jquery 的一个文本编辑框架
wineer200
博客等级 码龄19年 8粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值