白狼King 2016-08-05 11:22 采纳率: 26.3%
浏览 1514

前端接收不到后台的值,求大神解决,在线等,解决了速度结贴。。。。。。。。。。。。。。。。。。。。

package com.togest.emis.modules.g6c.web;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
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.togest.emis.framework.orm.Page;
import com.togest.emis.framework.orm.PropertyFilter;
import com.togest.emis.framework.utils.ConvertUtils;
import com.togest.emis.framework.utils.JSONParserUtils;
import com.togest.emis.framework.utils.RequestParamUtils;
import com.togest.emis.framework.utils.StringHelper;
import com.togest.emis.modules.g6c.entity.Download;
import com.togest.emis.modules.g6c.service.Downloadservice;
import com.togest.emis.modules.system.cache.SystemCache;
import com.togest.emis.modules.system.config.SystemConstants;

/**

  • @author mmk
  • */
    @Controller
    @RequestMapping(value = "/6c/system/download")
    public class DownloadController {
    @Autowired
    private Downloadservice service;
    @RequestMapping(method = RequestMethod.GET)
    public String list(Model model, HttpServletRequest request, String id) {
    model.addAttribute("psn_id", id);
    model.addAttribute(SystemConstants.NAV_PATH,
    SystemCache.getPath(id, RequestParamUtils.getUserID(request)));
    return "/6c/download";
    }

    @RequestMapping(value = "getPage", method = RequestMethod.POST)
    public void getPage(HttpServletRequest request,
    HttpServletResponse response, String name, String address ,Model model) {
    Map map = new HashMap();
    try {
    List filters = PropertyFilter
    .buildFromHttpRequest(request);
    Page page = RequestParamUtils
    .getPage(request, new Page());
    if (!page.isOrderBySetted()) {
    page.setOrderBy(SystemConstants.OrderByField);
    page.setOrder(Page.ASC);
    page = service.findPage(page, filters);
    }
    map.put(SystemConstants.EASYTABLE_PAGE_TOTAL_INDEX,
    page.getTotalCount());
    map.put(SystemConstants.EASYTABLE_PAGE_RESULT_INDEX,
    page.getResult());
    } catch (Exception e) {
    e.printStackTrace();
    }
    try {
    JSONParserUtils.write(response, JSONObject.fromObject(map)
    .toString());
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public void save(@RequestParam(value = "file", required = false) MultipartFile file,
    HttpServletRequest request, Model model,HttpServletResponse response, Download d,Map map) {
    String path = request.getSession().getServletContext()
    .getRealPath("download");

    String fileName = request.getParameter("name");
    String fileContent = file.getOriginalFilename();
    String fileType = fileContent.substring(fileContent.lastIndexOf("."));
    String fileAll = fileName+fileType;
    String address = path+"\"+fileAll;
    String file_path = address.substring(address.lastIndexOf("download"));
    String fileUrl = request.getContextPath() + "/download/"
    + fileAll;
    // //String fileName = new Date().getTime()+".jpg";
    File targetFile = new File(path, fileAll);
    if (!targetFile.exists()) {
    targetFile.mkdirs();
    }

    // 保存
    try {
        file.transferTo(targetFile);
    } catch (Exception e) {
        e.printStackTrace();
    }
    map.put("fileAll", fileAll);
    model.addAttribute("address", address);
    model.addAttribute("path", path);
    model.addAttribute("fileAll", fileAll);
    model.addAttribute("fileUrl",fileUrl);
    model.addAttribute("fileName", fileName);
    System.out.println("+++++++++++++++"+ fileAll);
        if (StringHelper.isBlank(d.getId())) {
        d.setId(null);
    }
    //d.setFile(fileAll);
    d.setAddress(file_path);
    service.save(d);
    map = new HashMap<String, Object>();
    map.put("msg", "新增成功");
    try {
        JSONParserUtils.write(response, JSONObject.fromObject(map)
                .toString());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

    }

    @RequestMapping(value = "edit", method = RequestMethod.GET)
    public void edit(HttpServletRequest request, HttpServletResponse response) {
    String id = RequestParamUtils.getStringParamter(request, "id");

    if (id != null) {
        Download d = service.get(id);
        try {
            Map<String, Object> map = ConvertUtils.objectToMap(d,
                    new String[] { "id", "sort", "name", "address" });
            JSONObject json = JSONObject.fromObject(map);
            JSONParserUtils.write(response, json.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    public void update(HttpServletResponse response, Download d) {
    service.save(d);
    Map map = new HashMap();
    map.put("msg", "修改成功");
    try {
    JSONParserUtils.write(response, JSONObject.fromObject(map)
    .toString());
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public void delete(HttpServletResponse response, String id) {
    Map map = new HashMap();
    String[] ids = id.split(",");
    service.delete(id);
    map.put("msg", "删除成功");

    try {
        JSONParserUtils.write(response, JSONObject.fromObject(map)
                .toString());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

    }

    @RequestMapping(value = "find", method = RequestMethod.POST)
    public String find(Model model, HttpServletRequest request) {
    List dlist = service.findAll();
    // for(Download d :dlist){
    // String dname =d.getName();
    // String daddress = d.getAddress();
    // request.setAttribute("dname", dname);
    // request.setAttribute("daddress", daddress);
    // }
    model.addAttribute("dlist", dlist);
    // ActionContext.getContext().getSession().put("dlist", dlist);
    // ActionContext.getContext().getValueStack().set("dlist", dlist);
    // request.setAttribute("dlist", dlist);
    return "/system/passport/login";
    }

}
这是控制器的代码
package com.togest.emis.modules.g6c.service;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.togest.emis.framework.orm.Page;
import com.togest.emis.framework.orm.PropertyFilter;
import com.togest.emis.modules.g6c.dao.DownloadDao;
import com.togest.emis.modules.g6c.entity.Download;
import com.togest.emis.modules.system.entity.P_Dictionary;
@Service
public class Downloadservice {
@Autowired
private DownloadDao dao;
/**
* 根据主键ID删除实体
*
* @param id
*/
public void delete(String id) {
dao.delete(id);
}

/**
 * 保存实体
 * 
 * @param entity
 */
public void save(Download entity) {
    dao.save(entity);
}

/**
 * 根据主键ID获取实体
 * 
 * @param id
 * @return
 */
public Download get(String id) {
    return dao.get(id);
}
/**
 * 查询所有
 */
public List<Download> findAll(){
    String hql ="FROM Download";
    List<Download> list = dao.find(hql);
    //for(Download d : list){
        //System.out.println("+++++++++++++"+d.getName());
    //}
    return list;

}
public Page<Download> findPage(final Page<Download> page,
        final List<PropertyFilter> filters) {
    return dao.findPage(page, filters);
}

}
业务层代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

  • 写回答

1条回答 默认 最新

  • 白狼King 2016-08-05 11:24
    关注

    !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



    <%@ include file="/common/meta.jsp"%>
    <%@ include file="/common/libs.jsp"%> $(function() { $('#dg').edatagrid({ sendParams : { 'sort' : 0 }, url : '${ctx}/6c/system/download/getPage', saveUrl : '${ctx}/6c/system/download/save', sourceUrl : '${ctx}/6c/system/download/edit', onDestroy : function(index, result) { $('#dg').datagrid('reload'); }, destroyUrl : '${ctx}/6c/system/download/delete', popdivId : 'dlg', //弹出层divid popformId : 'fm', //弹出层需要提交表单的id popTitle : '新增|编辑岗位信息'//弹出层标题 , , columns : [ [ { field : 'id', hidden : true, title : 'id' }, { field : 'sort', title : '排序', width : 200, align : 'center' }, { field : 'name', title : '插件名称', width : 200, align : 'center' }, { field : 'address', title : '插件链接', hidden: true, width : 200, align : 'center' }, ] ], rownumbers : true, singleSelect : true, toolbar : '#tb', pagination : true, method : 'post', nowrap : false, idField : 'id', pageList : [ 50, 100, 300, 500 ], pageSize : 50, fit : true }); }); function datagrid(action, obj) { $("#" + obj).edatagrid(action); } function ajax_search() { $("#dg").datagrid('load', { 'filter_LIKES_name' : $("#filter_LIKES_name").val() }); } //var address = document.getElementById("address").val(); //alert(address); //$("#upload").attr('src',address); $.extend($.fn.validatebox.defaults.rules, { checkPname : { validator : function(value) { var result = $.ajax({ async : false, cache : false, type : 'post', url : '${ctx}/system/base/position/checkPname', data : { 'pname' : value, 'id' : $("input[name='id']").val() } }).responseText; return result === "true"; }, message : '该名称已存在,请重新输入' } });


    <table id="dg" title="${navpath}">
    
    </table>
    
    
    <div id="tb"
        style="height: auto; color: #676767; padding-top: 6px; font-size: 14px;">
        <!-- 新增 -->
        <c:if test="${lbs:hasPermission(user_id,'DOWNLOADADD')==true}">
            <a class="easyui-linkbutton"
                data-options="iconCls:'icon-add',plain:true"
                onclick="javascript:$('#dg').edatagrid('create')">新增</a>
        </c:if>
    
    
        <!-- 编辑 -->
        <c:if test="${lbs:hasPermission(user_id,'DOWNLOADEDIT')==true}">
            <a class="easyui-linkbutton"
                data-options="iconCls:'icon-edit',plain:true"
                onClick="javascript: $('#dg').edatagrid('editlist');">编辑</a>
        </c:if>
    
    
    
        <!-- 删除 -->
        <c:if test="${lbs:hasPermission(user_id,'DOWNLOADDEL')==true}">
            <a class="easyui-linkbutton"
                data-options="iconCls:'icon-remove',plain:true"
                onClick="javascript:$('#dg').edatagrid('destroyRow')">删除</a>
        </c:if>
        <a class="easyui-linkbutton"
            data-options="iconCls:'icon-redo',plain:true"
            href="${ctx}/fileupload/download_file_url?fileDir=download&fileName=${fileAll}">下载</a>//这里取不到值
        <br />
        <div id="search_gid"
            style="margin-bottom: 4px; margin-top: 6px; font-size: 14px; padding-left: 5px; position: relative;">
            <input name="filter_LIKES_name" class="easyui-textbox"
                id="filter_LIKES_name"> <a class="easyui-linkbutton"
                style="width: 80px;"
                data-options="iconCls:'icon-search',plain:false"
                onclick="javascript:ajax_search()">查询</a>
    
        </div>
    
    </div>
    
    <div id="dlg" class="easyui-dialog"
        style="width: 650px; height: 450px; padding: 10px 20px; top: 20px; background: #f5f5f5"
        closed="true" buttons="#dlg-buttons_form">
    
        <form id="fm" class="fm" method="post" novalidate
            enctype="multipart/form-data">
            <!--  <input name="id" type="hidden">-->
            <div class="fitem">
                <label> 插件排序: </label> <input name="sort" class="easyui-numberbox"
                    style="height: 30px;" data-options="required:true" />
            </div>
    
            <div class="fitem">
                <label> 插件名称: </label> <input name="name" class="easyui-textbox"
                    id="filter_LIKES_name" style="height: 30px;" />
                <!-- data-options="required:true,validType:['checkPname','checkPname']" -->
            </div>
            <div class="fitem">
                <label> 插件上传: </label> <input type="file" id="upload" name="file"
                    style="height: 30px;" data-options="required:true" /> <img
                    id="test" style="display:none"
                    src="download" name="10202021" />
        </form>
        <div id="dlg-buttons_form">
            <a id="savebutton" class="easyui-linkbutton" iconCls="icon-save"
                onclick="javascript:$('#dg').edatagrid('save');save()"
                style="width: 90px;">保存</a> <a class="easyui-linkbutton"
                iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')"
                style="width: 90px">取消</a>
        </div>
    
        <script type="text/javascript">
            function save() {
                var url = document.getElementById("test").src;
                var name = document.getElementById("test").name;
                alert(url);
                alert(name);
            }
            //function save(){
            //var file = document.getElementById("upload");
            //alert(file);
            //$.ajax({
            // url : '${ctx}/6c/system/download/upload',
            //type : 'post',
            //data : {
            //file : file
            //},
            //dataType : "json",
            //success : function(result) {
            //},
            //error : function() {
    
            //}
            //});
    
            //}
        </script>
    


    前端页面代码

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题