gpt4 book ai didi

javascript - 在jsp中调用 Controller onclick

转载 作者:行者123 更新时间:2023-11-30 07:18:11 25 4
gpt4 key购买 nike

我正在使用Spring Web应用程序,在jsp文件中我必须使用ajax函数调用java文件中的 Controller ,我如何从jsp文件调用java文件中的 Controller 。

<p class="bottom-slide-corners">
<a class="billing" href="#Billing"><spring:message code="billing_area" /></a>
</p>


$('.billing').on('click', function(event) {
clearSliderInterval();
var $this = $(this);
var $linkToFind = $($this.attr("href") + "_billing");
var $slidesToFind = $("." + $this.attr("href").replace("#", "") + "_slide");

if($this.parent().parent().siblings('.current-arrow').find('img').is(":visible")) {
$this.parent().parent().siblings('.current-arrow').find('img:visible').slideUp();
$('.Background').slideUp(function() {
$(".learn_more").hide();
}).removeClass("open");
return false;
}

if($window.width() <= 767) {
$('#dashboard-mobile-banner, #header-bg, #footer-container, .container-slider').slideUp();

var categoryClass = $linkToFind.attr('id').replace("learnMore", "slide");
$('.courseDashboard').removeClass().addClass("courseDashboard Background " + categoryClass);
$('body, html').animate({ scrollTop: 0 }, "fast");
}

if($('.learn_more').is(":visible")) {
$('.Background').slideUp(function() {
$('.learn_more').hide();
$linkToFind.show();
$('.Background').slideDown();
});
} else {
$linkToFind.show();
$('.Background').slideDown(function() {
if ($window.width() <= 767) {
var slider = $("#" + $linkToFind.attr('id') + " .thumbview").bxSlider({
slideWidth: 300,
pager: false
});
$('.close-panel:visible').on('click', function(e) {
slider.destroySlider();
});
}
}).addClass("open");
}

$('.current-arrow img:visible').slideUp();
$slidesToFind.find('.current-arrow img').slideDown();
return false;
});

点击这里我想调用.java文件中的 Controller ,我如何在jsp文件代码中调用下面的 Controller ,点击

    @RequestMapping(value = "/billing", method = RequestMethod.POST)
public String Billing(@RequestParam Long caseId,
@RequestParam Long noteID, HttpServletRequest request) throws Exception {
try{

----------
logger.debug("success ");
return "success";
} catch (Exception e) {
logger.error(e,e);
throw e;
}}

最佳答案

你可以这样做......它会 100% 工作:) 。

(".billing").on('click',function(){
$.ajax({url:"/billing", success: function(result){

}});
})

返回 JSONObject 给出的映射中的成功字符串,将 key 保留为“result”和“成功”作为您的 String 。您在 Controller 中编写类似的内容

`JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("result", "success");
String myResult= jsonObject1.toString();
response.getWriter().write(myResult);`

如您所见,我添加了 resp.getWriter() 。它将响应发送回您的 Controller 。因此,还请在您的方法 public String Billing 方法中添加一个响应对象 HttpServletResponse resp,就像您添加的 HttpServletRequest 请求 一样。不要在 Controller 中添加 return 语句,并将 Controller 方法标记为 void这将 100% 有效。让我知道是否有帮助! :)

关于javascript - 在jsp中调用 Controller onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38040621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com