here, here, here의 답변을 확인했지만 제대로 작동하지 않습니다. 제 질문은 제가 양식을 제출하려 할 때 415 지원되지 않는 미디어 유형을 얻는 것과 같습니다. 심지어 우체부 클라이언트와 똑같은지 확인했습니다. 그래서 그것은 내 백 엔드 코드에서 뭔가 있어야합니다. 그러나 나는 그것을 얻을 수 없다.spring-mvc : 415 (지원되지 않는 미디어 유형) jquery
여기 여기 내 jQuery 코드
home='<%=request.getContextPath()%>';
function companyRegistration(){
var add = {}
var address={};
add["type"] = $("#type").val();
add["companyName"] = $("#companyName").val();
add["regNumber"] = $("#regNumber").val();
add["dob"] = $("#dob").val();
add["email"] = $("#email").val();
add["password"] = $("#password").val();
add["confirmPassword"] = $("#cpassword").val();
address["line1"] = $("#line1").val();
address["line2"] = $("#line2").val();
address["state"] = $("#state").val();
address["country"] = $("#country").val();
address["zipCode"] = $("#zipCode").val();
add["address"]=address;
add["enabled"]=false;
console.log("search: ", add);
console.log("stringify data:",JSON.stringify(add));
$.ajax({
type : "POST",
/* headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}, */
contentType: "application/json;charset=UTF-8",
url : home+"/addCompany",
data : JSON.stringify(add),
dataType : 'json',
timeout : 100000,
success : function(data) {
console.log("SUCCESS: ", data);
alert(data)
},
error : function(e) {
console.log("ERROR: ", e);
alert(e);
},done : function(e) {
console.log("DONE");
}
});
는 다시 해당 종료 코드
@RequestMapping(value="/addCompany",method=RequestMethod.POST,consumes=MediaType.APPLICATION_JSON_VALUE)
[email protected] String userLogin(@RequestBody CompanyRegVO user,HttpServletRequest req){
logger.debug("signUp user:"+user);
// get reCAPTCHA request param
String gRecaptchaResponse = req.getParameter("g-recaptcha-response");
boolean isVerified= Verify.verifyGcaptchResponse(gRecaptchaResponse);
ObjectMapper mapper=new ObjectMapper();
String jsonString="";
System.out.println("signUp user:"+user);
Integer id=null;
try{
if(isVerified){
id = signupHandler.process(user);
if(id!=null){
logger.debug("ID in controller:"+id);
emailHandler.sendVerificationMail(id,user.getEmail());
System.out.println("user create successfully");
}
jsonString=mapper.writeValueAsString("User creaated successfully");
}
else
jsonString= mapper.writeValueAsString("please verify that you are not a robot");
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
try {
jsonString=mapper.writeValueAsString(e.getMessage());
} catch (JsonProcessingException e1) {
}
return jsonString;
}
return "success";
}
내가 헤더와 내용 유형 및 동의를 추가하여 시도합니다.
public class CompanyRegVO {
private String companyName;
private Integer regNumber;
private String password;
private String confirmPassword;
private String type;
private String email;
private String dob;
private Boolean enabled;
private AddressVO address;
//getters and setters
}
따라서 내 설정 클래스
@Configuration
@ComponentScan(basePackageClasses={EmailHandler.class,CompanyRegVO.class,CompanyInfoDao.class,MainController.class,MyDBAuthenticationService.class,CompanyRegVO.class,ApplicationContextConfig.class,HibernateUtil.class,SendMail.class})
public class ApplicationContextConfig {
@Bean
public ResourceBundleMessageSource messageSource() {
ResourceBundleMessageSource rb = new ResourceBundleMessageSource();
// Load property in message/validator.properties
rb.setBasenames(new String[] { "messages/validator" });
return rb;
}
@Bean(name = "viewResolver")
public InternalResourceViewResolver getViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/pages/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
이 CompanyRegVO
나는 내 POM 잭슨 코어, 잭슨 - 매퍼 - ASL, 잭슨 데이터 바인딩 의존성을 가지고있다. 내가 어디가 잘못되었는지 알려주시겠습니까 ??편집 1 : 한 가지 내가 @RequestBody 주석을 제거하면이 여기
public class AddressVO {
private String line1;
private String line2;
private Integer zipCode;
private String state;
private String country;
//getter and setter
}
의 내 데이터 문자열 화 (stringification) 후 나는 콘솔
에있어 객체와이 내 addressVO 클래스를 추가의 나 잘 작동
캐릭터 라인 화 데이터 : {"type":"user","companyName":"k","regNumber":"0","dob":"16-10-1992","email":"[email protected]","password":"12345678","confirmPassword":"12345678","address":{"line1":"l3","line2":"l2","state":"k","country":"i","zipCode":"12"},"enabled":false}
Edit2가 : 내 네트워크 탭 사물의 몇 가지를 살펴 보자
Request URL:http://localhost:8080/basicPages/addCompany
Request Method:POST
Status Code:415 Unsupported Media Type
Remote Address:127.0.0.1:8080
**Response Headers**
view source
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Language:en
Content-Length:1091
Content-Type:text/html;charset=utf-8
Date:Sat, 07 Jan 2017 06:11:32 GMT
Expires:0
Pragma:no-cache
Server:Apache-Coyote/1.1
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
**Request Headers**
view parsed
POST /basicPages/addCompany HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 253
Accept: application/json
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Content-Type: application/json
Referer: http://localhost:8080/basicPages/signUp
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Cookie: JSESSIONID=0FFD6259AED6E75ABD62ED556AC125E4; oracle.uix=0^^GMT+5:30^p
**Request Payload**
view source
{type: "user", companyName: "k", regNumber: "1", dob: "16-10-1992", email: "[email protected]",…}
address:{line1: "l1", line2: "", state: "g", country: "i", zipCode: "1234"}
companyName:"k"
confirmPassword:"12345678"
dob:"16-10-1992"
email:"[email protected]"
enabled:false
password:"12345678"
regNumber:"1"
type:"user"
가 다시 서버에 일부 HTML 요소를 게시하는 날 것으로 보인다 내 직렬화 클래스입니다. 당신은'JSON.stringify (add)'를보실 수 있습니다.'add'는 어떤 원소도 포함하고 있지 않습니다. – Jai
"add"변수의 값을 어떻게 생성했는지 보여줄 수 있습니까? – Nimesh
추가 한 번만 참조하십시오 – LowCool