Home Database Mysql Tutorial ExtJS3.2+SpringMVC4.0 Form提交后返回json始终是failure,而且

ExtJS3.2+SpringMVC4.0 Form提交后返回json始终是failure,而且

Jun 07, 2016 pm 03:37 PM
form submit

经过一段折腾,总算把问题解决了,下面将解决的过程记录下来,希望能给其他人提供些帮助: 返回JSON式的数据,需要在ApplicationContext.xml中配置,当然网上有两种方法,我用了第一种,即阿里巴巴的fastjson,之前下载的是低版本的,运行时发现有错,因为缺

经过一段折腾,总算把问题解决了,下面将解决的过程记录下来,希望能给其他人提供些帮助:

返回JSON格式的数据,需要在ApplicationContext.xml中配置,当然网上有两种方法,我用了第一种,即阿里巴巴的fastjson,之前下载的是低版本的,运行时发现有错,因为缺少对spring的支持,最终下载了1.1.40版本(当然版本越高肯定也支持),将下载的fastjson-1.1.40.jar包加入到buildpath中。下面就要配置applicationcontext.xml了,配置代码如下:


       
           
           
               
                   
                       
                        text/html;charset=UTF-8
                        application/json;charset=UTF-8
                   

               

           

       

   

在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 = new HashMap();
  map.put("success", false);
  map.put("msg", "失败");
  return map;
 }





Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL transaction processing: the difference between automatic submission and manual submission MySQL transaction processing: the difference between automatic submission and manual submission Mar 16, 2024 am 11:33 AM

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 Tips for implementing form validation and submission with PHP and UniApp Jul 06, 2023 am 10:57 AM

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

Getting Started with Java Git: Exploring Version Control from Scratch Getting Started with Java Git: Exploring Version Control from Scratch Feb 23, 2024 am 10:25 AM

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 submission in Vue How to handle complex form submission in Vue Oct 15, 2023 pm 03:42 PM

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 How to handle form data verification and submission in Vue technology development Oct 09, 2023 am 08:12 AM

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 is renamed FORM again, and the FOUR it gives to the community is about to soar? BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? Mar 04, 2025 pm 12:00 PM

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

Can there be multiple forms in html5? Can there be multiple forms in html5? Aug 01, 2022 pm 05:28 PM

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>.....".

What is the tag that defines the form in html5 What is the tag that defines the form in html5 Jul 26, 2022 pm 04:26 PM

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.

See all articles