直接报500错误

直接报500错误

没有加验证码之前,做了一个小测试无法添加

http://img1.sycdn.imooc.com//climg/5c9a0ee60001baf405670300.jpg

$(function () {
    var initUrl = '/shopadmin/getshopinitinfo';
    var registerShopUrl = '/shopadmin/registerShop';
    getshopinitinfo();

    function getshopinitinfo() {
        $.getJSON(initUrl, function (data) {
            if (data.success) {
                var categoryHtml = '';
                var areaHtml = '';
                data.catagoryList.map(function (item, index) {
                    categoryHtml += '<option data-id="' + item.shopCategoryId + '">' + item.shopCategoryName + '</option>';
                })
                data.areaList.map(function (item, index) {
                    areaHtml += '<option data-id="' + item.areaId + '">' + item.areaName + '</option>';
                })
                $('#shop-category').html(categoryHtml);
                $('#shop-area').html(areaHtml);

                $('#submit').click(function () {
                    var shop = {};
                    shop.shopName = $('#shop-name').val();
                    shop.shopAddr = $('#shop-addr').val();
                    shop.phone = $('#shop-phone').val();
                    shop.shopDesc = $('#shop-desc').val();
                    shop.shopCategory = {
                        shopCategoryId: $('#shop-category').find('option').not(function () {
                            return !this.selected;
                        }).data('id')
                    }
                    shop.area = {
                        areaId: $('#shop-area').find('option').not(function () {
                            return !this.selected;
                        }).data('id')
                    }
                    // 获取上传的图片文件流
                    var shopImg = $('#shop-img')[0].files[0];
                    // 生成表单对象,用于接收参数并传递给后台
                    var formData = new FormData();
                    // 添加图片流进表单对象里
                    formData.append('shopImg', shopImg);
                    // 将shop json对象转成字符流保存至表单对象key为shopStr的的键值对里
                    formData.append('shopStr', JSON.stringify(shop));
                    console.log(shop)
                    $.ajax({
                        url: registerShopUrl,
                        type: 'POST',
                        data: formData,
                        contentType: false,
                        processData: false,
                        cache: false,
                        success: function (data) {
                            if (data.success) {
                                $.toast('提交成功!');
                            } else {
                                $.toast('提交失败!' + data.errMsg);
                            }
                        }
                    });
                });
            }
        })
    }
})
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>店铺信息</title>
    <meta name="description" content="MSUI: Build mobile apps with simple HTML, CSS, and JS components.">
    <meta name="author" content="阿里巴巴国际UED前端">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/favicon.ico">
    <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">

    <!-- Google Web Fonts -->

    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.css">
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.css">


    <script>
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "//hm.baidu.com/hm.js?ba76f8230db5f616edc89ce066670710";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

</head>
<body>
<div class="page-group">
    <div id="page-layout" class="page">
        <header class="bar bar-nav">
            <a class="button button-link button-nav pull-left back" href="/demos/form">
                <span class="icon icon-left"></span>
                返回
            </a>
            <h1 class="title">店铺信息</h1>
        </header>
        <div class="content">
            <div class="list-block">
                <ul>
                    <!-- Text inputs -->
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">店铺名称</div>
                                <div class="item-input">
                                    <input type="text" placeholder="店铺名称" id="shop-name">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-gender"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">商铺分类</div>
                                <div class="item-input">
                                    <select id="shop-category">

                                    </select>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-gender"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">所属区域</div>
                                <div class="item-input">
                                    <select id="shop-area">
                                    </select>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-email"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">详细地址</div>
                                <div class="item-input">
                                    <input type="text" placeholder="详细地址" id="shop-addr">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-email"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">联系电话</div>
                                <div class="item-input">
                                    <input type="text" placeholder="联系电话" id="shop-phone">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-email"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">缩略图</div>
                                <div class="item-input">
                                    <input type="file" placeholder="联系电话" id="shop-img">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li class="align-top">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-comment"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">店铺简介</div>
                                <div class="item-input">
                                    <textarea id="shop-desc"></textarea>
                                </div>
                            </div>
                        </div>
                    </li>

                </ul>
            </div>
            <div class="content-block">
                <div class="row">
                    <div class="col-50"><a href="#" class="button button-big button-fill button-danger">返回</a></div>
                    <div class="col-50"><a href="#" class="button button-big button-fill button-success"
                                           id="submit">提交</a></div>
                </div>
            </div>
        </div>
    </div>

</div>
<script type='text/javascript' src='/resources/js/shop/jquery-3.3.1.js'/>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.js' charset='utf-8'></script>
<script type='text/javascript'
        src='../resources/js/shop/shopoperation.js' charset='utf-8'></script>

</body>
</html>
进到后台无法获取到值


正在回答

登陆购买课程后可参与讨论,去登陆

5回答

同学有没有在这个spring-web.xml 中配置文件上传解析器呢?

http://img1.sycdn.imooc.com//climg/5c9ae94d0001149f13560390.jpg

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

提问者 慕无忌6012795 2019-03-27 11:48:49

http://img1.sycdn.imooc.com//climg/5c9af2710001db9910640316.jpg

注释的是我写的,上面是cp老师的,为什么老师的可以,而我的不行

  • 同学加上id="multipartResolver" 这个属性试试呢? 祝学习愉快
    2019-03-27 13:43:59
提问者 慕无忌6012795 2019-03-27 10:38:50

http://img1.sycdn.imooc.com//climg/5c9ae20a0001971012740353.jpg

加了验证码后 , 验证码也是获取不到,也是直接报错了

好帮手慕阿莹 2019-03-27 10:04:50

建议同学在HttpServletRequestUtil 的getString方法中,在几个地方打个断点或者写个输出语句,

看看在,并且打印一下result,看看是否接收到了result这个参数,又进入到了那个语句中

http://img1.sycdn.imooc.com//climg/5c9ad9ba000106ac09180324.jpg

我们一点点排查

祝学习愉快

  • 提问者 慕无忌6012795 #1
    老师,在上面发出来了,帮忙查看
    2019-03-27 10:39:22
提问者 慕无忌6012795 2019-03-26 19:38:54
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星

相似问题

登录后可查看更多问答,登录/注册

请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师