1、编写的页面

<%@ page language="java" contentType="text/html; charset=UTF-8"

 pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">

<meta name="apple-mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-status-bar-style" content="black">

<meta name="format-detection" content="telephone=no">

<title>XXX</title>

<script type="text/javascript" src="<c:url value="/resources/cartoon2/js/jquery-1.7.2.min.js"/>"></script>

<script type="text/javascript" src="<c:url value="/resources/js/jquery.js"/>"></script>

<script language="javascript" type="text/javascript" src="<c:url value="/resources/js/jquery-2.1.1.js"/>"></script>



<script type='text/javascript' src='<c:url value="/resources/js/jquery.validate.min.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/js/jquery.validate.cn.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/jqueryform/2.8/jquery.form.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/js/jquery.validate.js"/>'></script>



<script type='text/javascript' src='<c:url value="/resources/upload/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/upload/jQuery-File-Upload/js/jquery.iframe-transport.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/upload/jQuery-File-Upload/js/jquery.fileupload.js"/>'></script>

<script type='text/javascript'>

$(function(){

var basePath = "${pageContext.request.contextPath}";

$('#upload').fileupload({

dataType : 'json',

// autoUpload: true,

url : "/report/createReport",



done : function(e, data) {

$.each(data.result,function(index, file) {

if (index == 'filedesc') {

var _path = file.filepath + '/' + file.filename;

$('#posterUrl').val(_path);

$('#imgfileName').val(file.filename);

} else if(index == "suffixError") {

alert(file);

}

});

},

});



$("#upimgid").click(function() {

//alert("test");

$("#upload").trigger('click');

});



$("#reportButton").click(function(){

var flag = true;



//获取标题信息

var title = $("#title").val();

//获取描述信息

var description = $("#description").val();

//获取图片路径

var image = $("#posterUrl").val();

//获取名称

var name = $("#name").val();

//获取联系方式

var contact = $("#contact").val();



if(title == "") {

$("#title").attr("placeholder","标题不能为空!");

flag = false;

}

if(image == "") {

$("#posterUrl").attr("placeholder","图片不能为空!");

flag = false;

}

if(description == "") {

$("#description").attr("placeholder","描述信息不能为空!");

$("#imgfileName").attr("placeholder","描述信息不能为空!");

flag = false;

}



if(flag == true) {

jQuery.ajax({

type : 'POST',

url : basePath + "/report/createReport",

data : {

"title" : title,

"description" : description,

"name" : name,

"contact" : contact,

"image":image

},

dataType : 'json',

success : function(data) {

console.log(data);

if(data.result == "success") {

$("#title").val("");

$("#posterUrl").val("");

$("#description").val("");

$("#posterUrl").val("");

$("#imgfileName").val("");

$("#name").val("");

$("#contact").val("");

alert("信息提交成功!");



//window.opener=null;

window.close();



} else if(data.result == "fail") {

alert("对不起,信息提交失败!");

}

},

error : function() {

alert("网络或者其他原因出错!");

}

});

}

});

});



</script>

<style type="text/css">

body,html *{

margin:0px;

padding:0px;

}

#report-header{

color:#fff;

font-weight:900;

height:3em;

line-height:3em;

padding-left:2.8em;

background:RGB(0,171,240) url("../resources/report/icon.gif") no-repeat 1.2em 0.9em !important;

margin-bottom:1.6em;

}

#report-form {

text-align:center;

padding-left:3%;

}

#report-form table {

width:94%;

text-align:center;

}

#report-form table tr td,#report-form table tr td input,#report-form table .field-name,#report-form #star{

height:25px;

line-height:25x;

vertical-align: middle;

}



#report-form table .field-name{

text-align:left;

font-weight:800;

color:#888888;

width:24%;

vertical-align:top;

}

#report-form table input,#report-form table textarea {

border-width: 1px;

border-style:solid;

-moz-border-radius:3px;

-khtml-border-radius:3px;

-webkit-border-radius:3px;

border-radius:3px;

border-color:#bbbbbb;

-moz-border-color:#bbbbbb;

color:#888888;

outline-style:none;

width:98%;

font-size:16px;

}

input {-webkit-appearance:none;}

input[type="submit"],input[type="reset"],input[type="button"],input{-webkit-appearance:none;}

#report-form table .field-input {

text-align:left;

}

#report-form table .field-name .character{

margin-right:0.3em;

}

#report-form table #imgfileName {

width:87%;

float:left;

border-bottom-right-radius:0px;

border-top-right-radius:0px;

}

#report-form table #upimgid{

width:10%;

float:left;

color:#888888;

height:27px;

border-left:0px;

border-bottom-left-radius:0px;

border-top-left-radius:0px;

}

#report-form #star{

color:red;

}

#report-form #reportButton{

width:100%;

text-align:center;

color:#fff;

height:40px;

font-weight:900;

vertical-align:middle;

background:RGB(0,171,240) !important;

}



</style>

</head>

<body>

<div id="report-header">

问题反映

</div>

<div id="report-form">

<form action="" method="post" enctype="multipart/form-data">

<table>

<tr>

<td class="field-name"><label class="character">标题</label><label id="star">*</label></td>

<td class="field-input" style="padding-bottom:25px;">

<input type="text" name="title" id="title"/>

</td>

</tr>

<tr>

<td class="field-name"><label class="character">描述</label><label id="star">*</label></td>

<td class="field-input" style="padding-bottom:25px;">

<textarea rows="4" name="description" id="description"></textarea>

</td>

</tr>

<tr>

<td class="field-name"><label class="character">图片</label><label id="star">*</label></td>

<td class="field-input" style="padding-bottom:25px;">

<c:url value="/report/upLoadZipNormal" var="fileUploadUrl" />

<input id="upload" type="file" name="file"

data-url="${fileUploadUrl}" multiple

style="opacity: 0; filter: alpha(opacity :0); display: none;" />

<input id="posterUrl" name="posterUrl" type="hidden"/>

<input id="imgfileName" name="imgfileName" type="text" />

<input type="button" id="upimgid" value="+"/>

</td>

</tr>

<tr>

<td class="field-name">姓名</td>

<td class="field-input" style="padding-bottom:25px;">

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

</td>

</tr>

<tr>

<td class="field-name">联系方式</td>

<td class="field-input" style="padding-bottom:35px;">

<textarea rows="2" name="contact" id="contact"></textarea>

</td>

</tr>

<tr class="button-tr">

<td colspan="2" id="reportButton" id="reportButton">

提交

</td>

</tr>

</table>

</form>

</div>

</body>

</html>

<title>全国政府网站普查</title>

<script type="text/javascript" src="<c:url value="/resources/cartoon2/js/jquery-1.7.2.min.js"/>"></script>

<script type="text/javascript" src="<c:url value="/resources/js/jquery.js"/>"></script>

<script language="javascript" type="text/javascript" src="<c:url value="/resources/js/jquery-2.1.1.js"/>"></script>

<script type='text/javascript' src='<c:url value="/resources/js/jquery.validate.min.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/js/jquery.validate.cn.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/jqueryform/2.8/jquery.form.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/js/jquery.validate.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/upload/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/upload/jQuery-File-Upload/js/jquery.iframe-transport.js"/>'></script>

<script type='text/javascript' src='<c:url value="/resources/upload/jQuery-File-Upload/js/jquery.fileupload.js"/>'></script>

<script type='text/javascript'>

$(function(){

 var basePath = "${pageContext.request.contextPath}";

 $('#upload').fileupload({

  dataType : 'json',

  // autoUpload: true,

  url : "/report/createReport",

done : function(e, data) {

   $.each(data.result,function(index, file) {

    if (index == 'filedesc') {

     var _path = file.filepath + '/' + file.filename;

     $('#posterUrl').val(_path);

     $('#imgfileName').val(file.filename);

    } else if(index == "suffixError") {

     alert(file);

    }

   });

  },

 });

 

 $("#upimgid").click(function() {

  //alert("test");

  $("#upload").trigger('click');

 });

 

 $("#reportButton").click(function(){

  var flag = true;

//获取标题信息

  var title = $("#title").val();

  //获取描述信息

  var description = $("#description").val();

  //获取图片路径

  var image = $("#posterUrl").val();

     //获取名称

  var name = $("#name").val();

  //获取联系方式

  var contact = $("#contact").val();

if(title == "") {

       $("#title").attr("placeholder","标题不能为空!");

       flag = false;

  }

  if(image == "") {

   $("#posterUrl").attr("placeholder","图片不能为空!");

   flag = false;

  }

        if(description == "") {

   $("#description").attr("placeholder","描述信息不能为空!");

   $("#imgfileName").attr("placeholder","描述信息不能为空!");

   flag = false;

  }

if(flag == true) {

   jQuery.ajax({

    type : 'POST',

    url : basePath + "/report/createReport",

    data : {

     "title" : title,

     "description" : description,

     "name" : name,

     "contact" : contact,

     "image":image

    },

    dataType : 'json',

    success : function(data) {

     console.log(data);

     if(data.result == "success") {

      $("#title").val("");

      $("#posterUrl").val("");

      $("#description").val("");

      $("#posterUrl").val("");

                        $("#imgfileName").val("");

      $("#name").val("");

      $("#contact").val("");

      alert("信息提交成功!");

      

      //window.opener=null;

      window.close();

                       

     } else if(data.result == "fail") {

      alert("对不起,信息提交失败!");

     }

    },

    error : function() {

     alert("网络或者其他原因出错!");

    }

   });

  }

 });

});

</script>

<style type="text/css">

    body,html *{

        margin:0px;

        padding:0px;

    }

    #report-header{

        color:#fff;

        font-weight:900;

        height:3em;

        line-height:3em;

        padding-left:2.8em;

        background:RGB(0,171,240) url("../resources/report/icon.gif") no-repeat 1.2em 0.9em !important;

        margin-bottom:1.6em;

    }

    #report-form {

  text-align:center;

        padding-left:3%;

    }

    #report-form table {

        width:94%;

        text-align:center;

    }

    #report-form table tr td,#report-form table tr td input,#report-form table .field-name,#report-form #star{

        height:25px;

        line-height:25x;

        vertical-align: middle;

    }

#report-form table .field-name{

        text-align:left;

        font-weight:800;

        color:#888888;

        width:24%;

        vertical-align:top;

    }

    #report-form table input,#report-form table textarea {

     border-width: 1px;

     border-style:solid;

     -moz-border-radius:3px;

        -khtml-border-radius:3px;

        -webkit-border-radius:3px;

        border-radius:3px;

        border-color:#bbbbbb;

        -moz-border-color:#bbbbbb;

        color:#888888;

        outline-style:none;

        width:98%;

  font-size:16px;

    }

 input {-webkit-appearance:none;}

    input[type="submit"],input[type="reset"],input[type="button"],input{-webkit-appearance:none;}

    #report-form table .field-input {

        text-align:left;

    }

    #report-form table .field-name .character{

        margin-right:0.3em;

    }

 #report-form table #imgfileName {

        width:87%;

  float:left;

  border-bottom-right-radius:0px;

  border-top-right-radius:0px;

    }

 #report-form table #upimgid{

  width:10%;

  float:left;

  color:#888888;

  height:27px;

  border-left:0px;

  border-bottom-left-radius:0px;

  border-top-left-radius:0px;

 }

    #report-form #star{

     color:red;

    }

    #report-form #reportButton{

     width:100%;

        text-align:center;

        color:#fff;

        height:40px;

        font-weight:900;

        vertical-align:middle;

        background:RGB(0,171,240) !important;

    }

   

</style>

</head>

<body>

    <div id="report-header">

         问题反映          

    </div>

 <div id="report-form">

  <form action="" method="post" enctype="multipart/form-data">

   <table>

    <tr>

     <td class="field-name"><label class="character">标题</label><label id="star">*</label></td>

     <td class="field-input" style="padding-bottom:25px;">

      <input type="text" name="title" id="title"/>

     </td>

    </tr>

    <tr>

     <td class="field-name"><label class="character">描述</label><label id="star">*</label></td>

     <td class="field-input" style="padding-bottom:25px;">

         <textarea rows="4" name="description" id="description"></textarea>

     </td>

    </tr>

    <tr>

     <td class="field-name"><label class="character">图片</label><label id="star">*</label></td>

     <td class="field-input" style="padding-bottom:25px;">

      <c:url value="/report/upLoadZipNormal" var="fileUploadUrl" />

            <input id="upload" type="file" name="file"

             data-url="${fileUploadUrl}" multiple

             style="opacity: 0; filter: alpha(opacity :0); display: none;" />

            <input id="posterUrl" name="posterUrl" type="hidden"/>

      <input id="imgfileName" name="imgfileName" type="text" />

      <input type="button" id="upimgid" value="+"/>

     </td>

    </tr>

    <tr>

     <td class="field-name">姓名</td>

     <td class="field-input" style="padding-bottom:25px;">

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

     </td>

    </tr>

    <tr>

     <td class="field-name">联系方式</td>

     <td class="field-input" style="padding-bottom:35px;">

         <textarea rows="2" name="contact" id="contact"></textarea>

     </td>

    </tr>

    <tr class="button-tr">

     <td colspan="2" id="reportButton" id="reportButton">

      提交

     </td>

    </tr>

   </table>

  </form>

 </div>

</body>

</html>

2.SpringMVC

package com.report.controller;

import java.io.InputStream;

import java.util.HashMap;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

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

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.multipart.MultipartFile;

import com.report.common.CommonVar;

import com.report.entity.Affix;

import com.report.entity.Report;

import com.report.service.IReportService;

import com.report.utils.FileUtils;

@Controller

@RequestMapping(value="/report",method = {

 RequestMethod.GET,

 RequestMethod.POST

})

public class ReportController {

 private static final Logger logger = Logger.getLogger(ReportController.class);

 

 @Autowired

 private IReportService reportService;

 //@Autowired

 //OperateImage operatorImage;

 

 /**

  * 用于跳转到报表的首页

  * @return

  */

 @RequestMapping(value = "/reportIndex")

 public String reportIndex(){

  return "/web/report/report";

 }

 

 /**

  * 用于创建报表用

  * @return

  */

 @RequestMapping(value = "/createReport"

   ,method = RequestMethod.POST,

   produces = "application/json")

 public Map<String, Object> createReport(

   Model model,HttpServletRequest request){

  Map<String, Object> result = new HashMap<String, Object>();

  result.put("result", "fail");

  

  //获取各种参数信息

  //获取标题

  String title = request.getParameter("title");

  //获取描述信息

  String description = request.getParameter("description");

  //获取图片地址

  String image = request.getParameter("image");

  //获取姓名

  String name = request.getParameter("name");

  //获取联系方式

  String contact = request.getParameter("contact");

  

  //创建一个举报实体

  Report report = new Report(

    title, description, image, name, contact);

  //保存举报信息

  boolean flag = reportService.createReport(report);

  if (flag) {

   result.put("result", "success");

  }

  

  return result;

 }

 

 /*private void zoomOutImg(String saveURL) throws IOException {

  int ratio = operatorImage.getImgRatio(saveURL, CommonVar.LOGO_SCALE);

  operatorImage.reduceImageEqualProportion(saveURL, saveURL, ratio);

 }*/

 

 /**

  * 上传到正式路径,压缩不截图

  *

  * @param param

  * @param imageFile

  * @return

  */

 @RequestMapping(value = "/upLoadZipNormal", method = RequestMethod.POST, produces = "application/json")

 public Map<String, Object> upLoadZipNormal(

   @RequestParam Map<String, String> param,

   @RequestParam("file") MultipartFile imageFile) {

  logger.info("-------------------");

  Map<String, Object> result = new HashMap<String, Object>();

  

  

  if (!imageFile.isEmpty()) {

   Map<String, String> filedesc = new HashMap<String, String>();

try {

    // 新文件名uuid形成的文件名称

    String uuid = FileUtils.genFileName();

// 存放路径

    String path = CommonVar.getStoreFilepath()

      + FileUtils.genFilePath(Affix.UGCFILE);

    path = path.replace("\\", "/").replace("//", "/");

    

    // 原文件名

    String srcName = imageFile.getOriginalFilename();

    String suffix = srcName.substring(srcName.lastIndexOf(".") + 1,srcName.length()).toLowerCase();

    if (suffix.length() != 0 && (suffix.equals("jpg")) || (suffix.equals("png"))) {

     // 带后缀的新文件名

     String newFileName = uuid

       + srcName.substring(srcName.indexOf("."));

// 保存文件路径(正式文件夹下)

     String saveURL = path + "/" + newFileName;

     

     // 写文件

     InputStream fi = imageFile.getInputStream();

FileUtils.writeFile(fi, saveURL);

     

     //等比缩图

     //zoomOutImg(saveURL);

String webpath = CommonVar.getWebStoreFilepath() + FileUtils.genFilePath("3");

     webpath = webpath.replace("\\", "/");

filedesc.put("id", uuid);

     filedesc.put("name", uuid);

     filedesc.put("filetype", Affix.UGCFILE);

     filedesc.put("contenttype", imageFile.getContentType());

     filedesc.put("filename", newFileName);// 有后缀

     filedesc.put("originalfilename", imageFile.getOriginalFilename());

     filedesc.put("filepath", webpath);

result.put("filedesc", filedesc);

    } else {

        result.put("suffixError","文件必须为RGB模式的JPG或PNG格式!"); 

    }

    

    //TODO 这里还要计算图片的像素大小。

   } catch (Exception e) {

    e.printStackTrace();

   }

  }

  

  return result;

 }

}




编写手机端自适应页面案例,springMVC代码,SpringMVC上传代码,去掉input框中原有的样式,使ios按钮没有圆角,css中的border-radius类似的更多相关文章

  1. jquery photoClip支持手机端,PC端 本地裁剪图片后上传插件

    支持手机,PC最好的是jquery photoClip插件,下载地址&示例:https://github.com/topoadmin/photoClip demo.html 代码: <! ...

  2. java免费空间!最简单的openshift免费空间上传代码教程!和FTP一样简单!

    史上最简单的openshift免费空间上传代码教程!没有之一! 最近因为想弄一个免费的空间,而且最好是Java的空间,找了一大片,jsp的空间少不说,免费的更是寥寥无几. 找了一大推垃圾空间,终于让我 ...

  3. 前端切图:手机端自适应布局demo

    手机端自适应布局demo原型如下: 图片发自简书App 要求如下:适应各种机型源码如下: <!DOCTYPE html > <html> <head> <me ...

  4. SpringMVC 实现文件上传与下载,并配置异常页面

    目录 上传文件的表单要求 Spring MVC实现上传文件 需要导入的jar包 配置MultipartResolver解析器 编写接收上传文件的控制器 Spring MVC实现文件下载 下载文件时的h ...

  5. Spring(七)SpringMVC的文件上传

    1-SpringMVC的请求-文件上传-客户端表单实现(应用) 表单项type="file" 表单的提交方式是post 表单的enctype属性是多部分表单形式,及enctype= ...

  6. SpringMVC文件的上传与下载实现

    单文件上传 首先创建项目,开发工具是IDEA,选择Spring项目,勾选上Spring和SpringMVC. 然后命名,最后完成. 默认生成配置文件在web/WEB-INF下. 首先导入需要的jar包 ...

  7. SpringMVC的文件上传下载,异常处理,拦截器的小总结

    文件的上传和下载 我们通常在访问网页时会使用到文件的上传与下载的功能,那么他是如何实现的呢? 1 下载: ResponseEntity :用于控制器方法的返回值类型,该控制器方法的返回值就是响应到浏览 ...

  8. 使用webstom或者idea上传代码到github或coding

    鉴于github网络速度太慢,建议用coding.先介绍github上传方式,因为webstom或idea集成了github,方法简单. git是一个版本控制器,他的作用是管理代码.比如你修改了代码, ...

  9. SpringMVC学习--文件上传

    简介 文件上传是web开发中常见的需求之一,springMVC将文件上传进行了集成,可以方便快捷的进行开发. springmvc中对多部件类型解析 在 页面form中提交enctype="m ...

随机推荐

  1. jQuery简单笔记

    jQuery 是一个 JavaScript 库,简化了 JavaScript 的编程. 语法:$(selector).action() selector 是字符串,表示HTML元素. 对象 符号 例子 ...

  2. 利用Runtime实现简单的字典转模型

    前言 我们都知道,开发中会有这么一个过程,就是将服务器返回的数据转换成我们自己定义的模型对象.当然服务器返回的数据结构有xml类型的,也有json类型的.本文只讨论json格式的. 大家在项目中一般是 ...

  3. c# 虚拟路径转化为物理路径

    string strPhycicsPath= Server.MapPath(path);

  4. idea和androidstudio的首次git配置一些问题

    网上都有很清楚的步骤 但是 都是教怎么使用 但是对第一次应用idea内部vcs的git 则很少有详细说明 首先要在网上创建个项目 然后本地git clone下来 不建议内部vcs的fetch from ...

  5. WeihanLi.Npoi

    WeihanLi.Npoi Intro Npoi 扩展,适用于.netframework4.5及以上和netstandard2.0, .netframework基于NPOI, .netstandard ...

  6. 使用python scipy.optimize linprog和lingo线性规划求解最大值,最小值(运筹学学习笔记)

    1.线性规划模型: 2.使用python scipy.optimize linprog求解模型最优解: 在这里我们用到scipy中的linprog进行求解,linprog的用法见https://doc ...

  7. MongoDB 查询分析

    MongoDB 查询分析可以确保我们建议的索引是否有效,是查询语句性能分析的重要工具. MongoDB 查询分析常用函数有:explain() 和 hint(). 使用 explain() expla ...

  8. ARM C C++内存对齐

           ARM 系列处理器是 RISC (Reducded Instruction Set Computing)处理器.很多基于ARM的高效代码的程序设计策略都源于RISC 处理器.和很多 RI ...

  9. ROS机器人程序设计(原书第2版)补充资料 (玖) 第九章 导航功能包集进阶 navigation

    ROS机器人程序设计(原书第2版)补充资料 (玖) 第九章 导航功能包集进阶 navigation 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中 ...

  10. SpringMVC基础配置(通过注解配置,非xml配置)

    SpringMVC是什么,有多火,我这里就不再啰嗦了,SpringMVC比Struts2好用太多,我在学校的时候私下里两种都接触过,对比之后果断选择了SpringMVC,后来在做Android应用开发 ...