JspSmart中同时上传文件与表单信息
来源:互联网 发布:手机归属地数据库下载 编辑:程序博客网 时间:2024/04/28 23:38
实例:
register.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=gb2312"%><%@ page import="dao.StudentDao,bean.student"%><% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; request.setCharacterEncoding("gb2312");//防止中文乱码 %><html><body> <form action="/实验8/servlet/UploadServlet" method="post" enctype="multipart/form-data"> <div align="center" > <label>姓名: </label> <input name="stuname" type="text"/> <label>学号: </label> <input name="stuno" type="text"/> <label>年龄: </label> <input name="age" type="text"/> <label>电话号码: </label> <input name="phone" type="text"/> <br><br> <label>性别: </label> <input name="sex" type="radio" value="男" checked/> 男 <input name="sex" type="radio" value="女"/> 女<br><br> <label>照片: </label> <input name="picture" value="" type="file"/> <br><br> <input value="注册" type="submit"/> </form> <br> <hr></body></html>
UploadServlet.java 部分代码
public class UploadServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { //初始化 SmartUpload smartUpload = new SmartUpload(); ServletConfig config = this.getServletConfig(); smartUpload.initialize(config, request, response); try { //上传文件 smartUpload.upload(); //得到上传的文件对象 File smartFile = smartUpload.getFiles().getFile(0); String name = smartFile.getFileName(); //保存文件 smartFile.saveAs("/picture/"+name, smartUpload.SAVE_VIRTUAL); //传过来的注册数据 //只需要new SmartUpload().getRequest().getParameter(""))就能获取到相应的表单数据 stuname = smartUpload.getRequest().getParameter("stuname"); stuno = Integer.parseInt(smartUpload.getRequest().getParameter("stuno")); ....... } catch (SmartUploadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
0 0
- JspSmart中同时上传文件与表单信息
- 研究了三天的文件上传(jspsmart实现)file和text表单同时提交的问题
- JSPSmart实现文件上传时file和text表单同时提交的问题
- 研究了三天的文件上传(jspsmart实现)file和text表单同时提交的问题
- 文件上传(jspsmart实现)file和text表单同时提交的问题
- jspsmart实现文件的上传与下载
- jspSmart实现文件上传与下载
- 使用JspSmart文件上传
- jspsmart上传文件
- 使用JspSmart文件上传
- JSP—表单信息与图片同时上传
- 怎么在一个表单里面同时上传文件和文本信息??
- 关于在一个form表单里同时上传多个文件和文本信息的解决方案。。。
- spring mvc 实现多文件上传,且同时包含表单信息
- javaEE jspsmart 实现文件上传和下载
- web技术中,用jsp上传和下载文件(jspsmart)
- 表单校验与文件上传
- 使用FormData来提交表单同时上传文件到服务端
- Spring in action--Part4-Integrating Spring
- 基本算法练习四
- Jprofiler9的使用的关键步骤
- php接口安全问题探讨
- 如何用openssl 生成公钥-私钥对
- JspSmart中同时上传文件与表单信息
- 代理模式
- 微博抓页面PYTHON代码模板
- 欢迎使用CSDN-markdown编辑器
- Java初学阶段知识总结
- MVC ViewBag 传多个Model到视图
- cpp的STL之string
- kali linux安装完成后的更新源问题
- 前端做图,零基础如何学习数位板绘画?