首页 > 代码库 > fileupload form表单提交(包括文件上传)
fileupload form表单提交(包括文件上传)
需要的jar包:commons-fileupload-1.3.1.jar
示例代码:
package com.expai.servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.HashMap;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;import com.expai.util.JDBCUtil;public class PhotoDataServlet extends HttpServlet{ private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{ doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{ response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); JDBCUtil dbUtil = new JDBCUtil(); Integer number = 0; Integer pageNum = 0;// String size = null; if(request.getParameter("number")!=null){ number = Integer.parseInt(request.getParameter("number")); } if(request.getParameter("pageNum")!=null){ pageNum = Integer.parseInt(request.getParameter("pageNum")); }// if(request.getParameter("size")!=null){// size = new String(request.getParameter("size").getBytes("ISO-8859-1"), "UTF-8");// } if(number!=null&&pageNum!=null){// String sql = "select id,photoUrl from tb_photo_data where userId = "+userId +" limit "+Integer.parseInt(pageNum)*Integer.parseInt(number)+","+number; String sql = "select id,photoUrl,width,height from tb_photo_data limit "+pageNum*number+","+number; ArrayList<HashMap<String,Object>> listData =http://www.mamicode.com/ dbUtil.getDataListMapNew(sql); PrintWriter pWriter = response.getWriter(); JSONArray json = JSONArray.fromObject(listData); pWriter.flush(); pWriter.print(json); } }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。