Tag: spring mvc

如何在javascript文件中访问Spring MVC模型对象?

我正在使用spring 3 MVC,我有以下课程。 外部系统将使用以下URL调用我的应用程序: http://somehost/root/param1/param2/param3 我有一个spring MVC控制器方法如下: public ModelAndView showPage(@PathVariable(“param1”) String paramOne, @PathVariable(“param2”) String paramTwo, @PathVariable(“param3”) String paramThree, HttpServletResponse response) { SomeModel model = new SomeModel(paramOne, paramTwo, paramThree); return new ModelAndView(“SomeJsp”, “model”, model); } SomeModel.java public class SomeModel{ private String paramOne; private String paramTwo; private String paramThree; //constructor //setters and getters } SomeJsp.jsp //In this […]

如何在Spring项目中使用Ajax更新ac:forEach?

以下是AJAX代码,我在下拉列表中选择一个值,然后从控制器返回一个List。 当我返回列表时,我想使用AJAX结果更新c:forEach项。 AJAX $(document).ready(function() { $(“#byCollege”).change(function() { // Get and convert the data for sending // Example: This variable contains the selected option-text var collName = $(‘#byCollege’).val(); var studentName = ‘${salary}’; var json = {“name” : studentName, “collName” : collName}; // Send the data as an ajax POST request $.ajax({ url: “http://localhost:8080/AnnaUnivResults/mvc/byCollege”, type: ‘POST’, dataType: […]

每5秒自动刷新DIV内容代码不起作用

我使用Spring MVC在我的editStatus.jsp中我有以下代码每5个seocnds刷新一次DIV function refreshDiv(){ $.ajax({ url: ‘editStatus.jsp’ }).done(function(result) { $(‘#refreshDIV’).text(result); }); } 我的DIV代码是   : :   ${fn:length(StatusForm.totalSentRecipient)}   ${fn:length(StatusForm.totalNotSentRecipient)}   ${fn:length(StatusForm.totalInProgressRecipient)} 从上面的代码我想自动刷新以下,但同样不起作用   ${fn:length(StatusForm.totalSentRecipient)}   ${fn:length(StatusForm.totalNotSentRecipient)}   ${fn:length(StatusForm.totalInProgressRecipient)} URL刷新代码应该通过控制器吗? 我试过了 $(document).ready(function () { alert(‘Hi OutBound’); var seconds = 5000; // time in milliseconds var reload = function() { alert(‘Inside Reload’); $.ajax({ url: ‘editStatus.jsp’, cache: […]

jQuery Ajax文件上传:不存在所需的MultipartFile参数’file’

背景 我正在Java8上构建一个Spring MVC Web应用程序并在tomcat8上运行它。 除了这个信息,Spring版本是4.1.6.RELEASE和Servlet 3.1我给你的环境背景,因为一些问题解决者提到版本与这个错误有关。 我的代码 下面是root-context.xml 下面是我的FileController @Controller public class FileController { private static final Logger logger = LoggerFactory.getLogger(FileController.class); private static final String UploadFolder = “Files”; @RequestMapping(“/uploadFile”) @ResponseBody public void uploadFile(@RequestParam(“file”) MultipartFile file, HttpServletResponse response) throws IOException { String fileName = “”; PrintWriter script = response.getWriter(); if (!file.isEmpty()) { try { byte[] bytes […]

Spring Jquery Ajax Post上有400个错误请求

我在这个POST请求上收到400个错误请求。 知道这里的问题是什么吗? 日志在这里 。 调节器 @Controller public class AjaxController { @RequestMapping(value=”/addKeys”, method=RequestMethod.POST, consumes=”application/json; charset=UTF-8″) public ResponseEntity addKeys(@RequestParam(value=”keys”) ArrayList keys){ System.out.println(“::::::::::::::::::::::::::::::::::::::::::::::::::::::::::”+keys); } } 上下文servlet.xml中 阿贾克斯 tmpList = ‘[{“key”:”camera”,”label”:”Camera”},{“key”:”mobile”,”label”:”Mobile”}]’; $.ajax({ type: ‘POST’, url: ctx+’/ajx/addKeys’, data: JSON.stringify({“keys”: tmpList }), success: function(r){ if(r.model.status==’success’){ debugger; //glist.push(elem.key); //addToList(elem.key, elem.label); highlightInfoDisc(); } }, dataType: ‘json’, contentType: ‘application/json’ }); FireBug – URL http://localhost:8080/Di/ajx/addKeys […]

JQuery,JSON,Spring MVC – 动态加载选择选项

我有一个像这样的jsp表单……第二个选择框中的值,应该根据第一个选择框(国家)中的值加载状态。 我正在使用AJAX,JSON,Spring MVC来检索结果。 index.jsp的….. <form:checkboxes items="${skillsList}" path="skills" itemLabel="description" itemValue="id" delimiter="” /> <form:checkboxes items="${languagesList}" path="languages" itemLabel="description" itemValue="id" delimiter="” /> 控制器…. @RequestMapping(value=”stateslist.html”) public @ResponseBody List sectionList(@ModelAttribute(“search”) SearchForm search, @RequestParam(value=”countryId”, required=true) String countryId, ModelMap modelMap){ return stateService.getStates(countryId); } JQuery部分…. function getStates(){ $.getJSON( “stateslist.html”, {countryId: $(‘#country’).val()}, function(data) { var html = ”; var len = data.length; for(var i=0; i<len; […]

限制文件类型,大小,单个上载在jquery文件上传时不起作用

我正在尝试使用带有Spring MVC的blueimp jquery文件上传插件来上传excel文件。文件正在上传。 我想将文件类型限制为excel(xls,xlxs),也只允许单个文件上传。 我正在使用插件推荐的参数,也尝试添加add: callback来执行validation,它都不起作用。 请帮忙。 我正在使用的js文件(按相同顺序) jquery.min.js jquery.ui.widget.js jquery.iframe-transport.js jquery.fileupload.js bootstrap.min.js 我的HTML代码是 Select files… File Name File Size File Type Download javascript代码是: $(function() { ‘use strict’; // the location of your server-side upload handler: var url = ”; $(‘#fileupload’) .fileupload( { //this doesnt work add : function(e, data) { var uploadErrors = []; […]

通过Spring MVC下载带有ajax()POST请求的文件

我尝试下载文件。 该操作由ajax()发布请求触发。 请求以json格式将数据发送到控制器。 控制器生成文件(字节)并将其发回。 java脚本: function getLicenseFile() { $.ajax({ type: ‘POST’, url: ‘/licenses/rest/downloadLicenseFile’, dataType: ‘json’, contentType: ‘application/json;charset=UTF-8’, data: ko.mapping.toJSON(licenseModel), success: function (data) { console.log(“in sucess”) }, error:function (xhr, ajaxOptions, thrownError){ console.log(“in error”) } }); } 控制器: @RequestMapping(value = “/licenses/rest/downloadLicenseFile”, method = RequestMethod.POST) @ResponseStatus(value=HttpStatus.OK) @ResponseBody public void createLicenseFile(@Valid @RequestBody License license, HttpServletResponse response) throws Exception { […]

如何在Spring MVC中使用AJAX呈现视图

我正在使用Spring MVC,我需要对服务器进行异步调用,并且只刷新页面的一部分。 我实际拥有的是一个返回String的Controller。 我使用JQuery( .post() )函数调用Controller。 我的解决方案的问题是,当我使用ModelAndView作为返回类型时,我无法像我那样呈现JSP。 有没有办法返回已经呈现的视图? 提前致谢。 Neuquino

从浏览器中的javascript传递数组数据到使用ajax弹出mvc控制器

我想使用AJAX将数组从Web浏览器中的javascript传递给Spring MVC控制器 在javascript中,我有 var a = []; a[0] = 1; a[1] = 2; a[2] = 3; // how about multiple arrays as well? $.ajax({ type : “POST”, url : “/myurl”, data : //not sure how to write this, (“a=”+a), ? success : function(response) { // do something … }, error : function(e) { alert(‘Error: ‘ […]