2

I am working on simple Spring-MVC application(Not Maven) where I want to make a web service which returns a boolean but it gives a HTTP Status 406 – Not Acceptable error. Also I am trying to call a it from a JSP.

JSP :

 <form action="${pageContext.request.contextPath}/getformatretension" method="post" id="form">
  <p>
   loc 1: <input type="text" name="srcUrl" size="45" id="file" />
  </p>
   <p>  
            loc 2 : <input type="text" name="xlfUrl" size="45" id="xlffile"/>  
       </p><input type="Submit" value = "Submit">      
 </form>

Controller :

public class MyClassController {

    @RequestMapping(value = "/getformatretension", method = RequestMethod.POST)

    public ResponseEntity<Boolean> methodName(@RequestParam("srcUrl") String srcUrl
            ,@RequestParam("xlfUrl") String xlfUrl) throws IOException{

        int nReturnVal = JsoupParserHtml.test(xlfUrl, srcUrl); 
        String mimeType=  "text/plain;charset=UTF-8";
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", mimeType);
           if(nReturnVal ==  1) 
           { 
                System.out.println("Success");
                return new ResponseEntity<Boolean>(true,HttpStatus.OK);

           }
           else {
               System.out.println("error");
               return new ResponseEntity<Boolean>(false,HttpStatus.BAD_REQUEST);
           }

        }

Error :

HTTP Status 406 – Not Acceptable

Type Status Report

Description The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation.

FullStackDeveloper
  • 910
  • 1
  • 16
  • 40
Faisal
  • 81
  • 1
  • 1
  • 6

2 Answers2

1

406 from service means the response type service is returning is not provided in the Accept HTTP header in your Client request.

headers.add("Content-Type", "application/json");

check with above code.

Yusuf Kapasi
  • 577
  • 2
  • 9
-1

Try adding the following request header:

Accept: "*/*"
wolmi
  • 1,659
  • 12
  • 25
cbalano
  • 1
  • 1