ExtJS3.2+SpringMVC4.0 Form提交后返回json始终是failure,而且
经过一段折腾,总算把问题解决了,下面将解决的过程记录下来,希望能给其他人提供些帮助: 返回JSON式的数据,需要在ApplicationContext.xml中配置,当然网上有两种方法,我用了第一种,即阿里巴巴的fastjson,之前下载的是低版本的,运行时发现有错,因为缺
经过一段折腾,总算把问题解决了,下面将解决的过程记录下来,希望能给其他人提供些帮助:
返回JSON格式的数据,需要在ApplicationContext.xml中配置,当然网上有两种方法,我用了第一种,即阿里巴巴的fastjson,之前下载的是低版本的,运行时发现有错,因为缺少对spring的支持,最终下载了1.1.40版本(当然版本越高肯定也支持),将下载的fastjson-1.1.40.jar包加入到buildpath中。下面就要配置applicationcontext.xml了,配置代码如下:
在SpringMVC的控制层的代码如下:
@RequestMapping("/upload") //这是定义了路由,和本文讲的没什么关系
@ResponseBody //因为我不想返回视图,而是返回一个json数据,那么这边必须要用RespnseBody来注解
Object类型,并且通过Map的方式将success和message添加进去,这样到前台就会根据success的值来判断调用是否成功执行了
public Object doUpload(@RequestParam(value = "F_FileType", required = false) String sType,HttpServletRequest request,HttpServletResponse response) throws IOException{
/*下面这一段是文件上传的代码*/
MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request;
MultipartFile file = fileRequest.getFile("F_PicPath");
String path = request.getSession().getServletContext().getRealPath("upload")+"\\"+sType+"\\";
String fileName = file.getOriginalFilename();
//response.setContentType("application/json; charset=UTF-8");
File targetFile = new File(path, fileName);
if (!targetFile.exists()){
targetFile.mkdirs();
}
try{
file.transferTo(targetFile);
}catch(Exception e){
e.printStackTrace();
}
Map
map.put("success", false);
map.put("msg", "失败");
return map;
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL transaction processing: the difference between automatic submission and manual submission. In the MySQL database, a transaction is a set of SQL statements. Either all executions are successful or all executions fail, ensuring the consistency and integrity of the data. In MySQL, transactions can be divided into automatic submission and manual submission. The difference lies in the timing of transaction submission and the scope of control over the transaction. The following will introduce the difference between automatic submission and manual submission in detail, and give specific code examples to illustrate. 1. Automatically submit in MySQL, if it is not displayed

Tips for implementing form validation and submission with PHP and UniApp Introduction: When developing web pages or mobile applications, form validation and submission are essential functions. Form validation is used to check whether the data entered by the user conforms to specific rules, and submission saves or sends the data entered by the user to the server. This article will introduce the techniques of using PHP and UniApp to implement form validation and submission to help developers quickly implement front-end and back-end interaction functions. 1. PHP implements form validation. The following is a PHP form validation sample code for

Introduction to git Git is a distributed version control system, which means that each developer has a complete copy of the code base on their computer. This is different from a centralized version control system (such as Subversion or Perforce), which only has a central code repository. The benefit of distributed version control is that it makes collaboration more efficient because developers can work offline and synchronize with the central code base later. Installing Git To use Git, you need to install it on your computer first. You can download the installer for your operating system from the official Git website. After the installation is complete, you can enter git --version in the command line to check whether the installation was successful. Git basic concepts repository: Git

How to handle complex form submissions in Vue requires specific code examples. In Vue, to handle complex form submissions, you can use Vue's form processing methods and other related plug-ins or features to simplify the development process. This article will introduce how to use Vue and some other common plug-ins to handle complex form submissions, and provide specific code examples. 1. Two-way binding of form data One of the core features of Vue is the two-way binding of data. In form processing, we can use Vue instructions to achieve bidirectional communication between form data and views.

How to handle form data verification and submission in Vue technology development In Vue technology, processing form data verification and submission is a common and important task. In actual development, we often need to verify the form data entered by the user to ensure that it meets the specified format requirements and can be safely submitted to the back-end server. The following will introduce a common method of processing form data verification and submission, and provide specific code examples. Data verification in Vue, we can use the Vuelidate plug-in for form data

BinaryX's token name change: from BNX to FOUR, and then to FORM, the deep meaning behind strategic adjustments BinaryX recently changed the token symbol from $FOUR to $FORM, which has attracted widespread attention from the industry. This is not the first time BinaryX has changed its name, and its token symbol has undergone a transition from BNX to FOUR. This article will explore in-depth the strategic intentions behind this series of name change. 1. Token name change process and strategic considerations BinaryX initially launched the $BNX token based on the BNB chain in 2021 to support its Play-to-Earn (P2E) gaming ecosystem. In early 2024, in order to optimize the economic model, BinaryX divided $BNX and gradually expanded to GameF

There can be multiple forms in html5. The rules allow multiple form tags to be used in the same HTML page. However, in order to prevent the backend from not recognizing it when submitting, you need to add different IDs or classes to the form. The syntax is "<from action="url" id=" id value 1">Form element</from><from action="url" id="id value 2">Form element</from>.....".

The tag defining a form in HTML5 is "<form>". The form tag is used to create an HTML form (form field) for user input to collect and transfer user information. All content in the form will be submitted to the server; the syntax "<form action="Submit Address" method="Submit Method " name="form name">form control</form>". A form can contain one or more form elements, such as input, select, and textarea.
