我尝试在Spring MVC中向我的控制器发出查询。
我的操作代码是:
@RequestMapping(value = "/compile/{applicationId}", method = RequestMethod.GET)
public String compileApplication(@PathVariable Long applicationId, @RequestParam("email") String email) throws ApplicationNotFoundException {
...
}
但我收到了一个错误:
必需的字符串参数'email'不存在
我的main.js:
var runCompileModal = function (options) {
$(".modal-compile").each(function () {
var modalNode = $('<div class="modal fade" id="compileModal" tabindex="-1" role="dialog" aria-hidden="true">' +
'<div class="modal-dialog modal-dialog-sm">' +
' <div class="modal-content">' +
' <div class="modal-header">' +
' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
' <h4 class="modal-title text-center">compile ?</h4>' +
' </div>' +
' <div class="modal-body">' +
' <p class="margin-bottom-lg">Are you sure ?</p>' +
' <div class="form-group text-center">' +
' <label for="email">@ Mail:</label>' +
' <input class="form-control" name="email" id="email" type="text" style="border:solid 1px black; border-radius:5px; text-align:center; box-shadow:0 0 6px;" /> ' +
' </div>' +
' <div class="form-group text-center">' +
' <button type="button" class="modal-btn-yes btn btn-success btn-gradient margin-right-lg">' +
' <i class="fa fa-check"></i>' +
' <span>' + options.compileModal.yes + '</span>' +
' </button>' +
' <button type="button" class="modal-btn-no btn btn-danger btn-gradient" data-dismiss="modal">' +
' <i class="fa fa-warning"></i>' +
' <span>' + options.compileModal.no + '</span>' +
' </button>' +
' </div>' +
' </div>' +
' </div>' +
'</div>' +
'</div>');
$('body').append(modalNode);
modalNode.find('.modal-btn-yes').click(function () {
var email = document.getElementById('email');
location.href = $(this).data('url') + "/" + email.value;
});
modalNode.on('show.bs.modal', function (e) {
var button = $(e.relatedTarget);
var modal = $('#compileModal');
modal.find('.modal-title').html(button.data('title'));
modal.find('.modal-body p').html(button.data('content'));
modal.find('.modal-btn-yes').attr('data-url', button.data('url'));
});
});
}
我的app.html:
' <button title="' + compileTitle + '" class="btn btn-compile btn-gradient" data-toggle="modal" data-target="#compileModal" data-url="' + compileUrl + object.id + '" + data-title="' + compileModalTitle + '" + data-content="' + compileModalContent + '">' +
' <span class="glyphicon glyphicon-share"></span>' +
' </button>'
当我在网址中包含电子邮件参数时出现新错误:
TypeError:e为null
答案 0 :(得分:1)
对我看起来像
location.href = $(this).data('url') + "/" + email.value;
应该是
location.href = $(this).data('url') + "/?email="
+ URLEncoder.encode(email.value, "UTF-8");
虽然我可能走错了路。 (URLEncoder也需要修改。)
P.S。
使用TamperData插件或其他工具的FireFox允许拦截来自浏览器的流量。
答案 1 :(得分:-1)
这意味着您没有从前端(从客户端)传递电子邮件参数。