本文介绍了json帖子上有500个内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨 我遇到的问题似乎无法击中我的控制器,请帮助 下面的Web.xml。 < web -app xmlns:xsi = http://www.w3.org/2001/XMLSchema-instance xmlns = http://java.sun.com/xml/ ns / javaee xsi:schemaLocation = http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0。 xsd id = WebApp_ID version = 3.0 > < display-name > mvc_1 < / display-name > < welcome-file-list > < welcome-file > index。 html < / welcome-file > < / welcome-file -list > < servlet > < servlet-name > Jersey < / servlet-name > < servlet-class > com.sun.jersey.spi.container.servlet.ServletContainer < / servlet-class > < init-param > < param-name > com.sun.jersey.config.property.packages < ; / param-name > < param-value > org.user < / param-value > < / init-param > < load-on-startup > 1 < / load-on-startup > < / servlet > < servlet-mapping > < servlet-name > Jersey < / servlet-name > < url-pattern > / rest / * < / url-pattern > < / servlet-mapping > < / web-app > var sUsername = $( #tbUsername)。val(); var sPassword = $( #tbPassword )VAL(); var jsonObj = { username:sUsername, password:sPassword}; $ .ajax ({ url: http: // localhost:8080 / mvc_1 / rest / controller / doPosting,类型:' POST', dataType:' json', data : JSON .stringify(jsonObj), contentType: application / json; charset = utf-8,成功: function (data) { alert( success !!)},错误: function (XHR,status,er) { alert(XHR.status + : + er + : + status); } }); 以下控制器: @ Path ( / controller) public class UserController { @ POST @ Path ( / doPosting) @ Consumes ({MediaType.APPLICATION_JSON}) public String doPosting(用户用户){ String output = user.getUsername(); System.out.println(输出); String json = new Gson()。toJson(user); System.out.println( 嗨); return json; } } 解决方案 ( #tbUsername)。val(); var sPassword = ( #tbPassword)VAL(); var jsonObj = { username:sUsername, password:sPassword}; .ajax ({ url: http:// localhost:8080 / mvc_1 / rest / controller / doPosting,类型:' POST', dataType:' json', data: JSON .stringify(jsonObj), contentType: application / json; charset = utf-8,成功:功能(数据) { alert( success !!)},错误:功能(XHR,状态,呃) { alert(XHR.status + : + er + : + status); } }); 以下控制器: @ Path ( / controller) public class UserController { @ POST @ Path ( / doPosting) @ Consumes ({MediaType.APPLICATION_JSON}) public String doPosting(用户用户){ String output = user.getUsername(); System.out.println(输出); String json = new Gson()。toJson(user); System.out.println( 嗨); return json; } } HiHaving issues i cant seem to hit my controller, please helpWeb.xml below.<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>mvc_1</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <servlet> <servlet-name>Jersey</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>org.user</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping></web-app>var sUsername = $("#tbUsername").val();var sPassword = $("#tbPassword").val();var jsonObj = {"username":sUsername,"password":sPassword};$.ajax({url:"http://localhost:8080/mvc_1/rest/controller/doPosting",type:'POST',dataType:'json',data:JSON.stringify(jsonObj), contentType: "application/json; charset=utf-8",success: function(data){alert("success!!")},error:function(XHR,status,er){alert(XHR.status +" : "+er+" : "+status);}});Controller below:@Path("/controller")public class UserController {@POST@Path("/doPosting")@Consumes({ MediaType.APPLICATION_JSON })public String doPosting(User user) {String output = user.getUsername();System.out.println(output);String json = new Gson().toJson(user);System.out.println("Hi");return json;}} 解决方案 ("#tbUsername").val();var sPassword =("#tbPassword").val();var jsonObj = {"username":sUsername,"password":sPassword};.ajax({url:"http://localhost:8080/mvc_1/rest/controller/doPosting",type:'POST',dataType:'json',data:JSON.stringify(jsonObj), contentType: "application/json; charset=utf-8",success: function(data){alert("success!!")},error:function(XHR,status,er){alert(XHR.status +" : "+er+" : "+status);}});Controller below:@Path("/controller")public class UserController {@POST@Path("/doPosting")@Consumes({ MediaType.APPLICATION_JSON })public String doPosting(User user) {String output = user.getUsername();System.out.println(output);String json = new Gson().toJson(user);System.out.println("Hi");return json;}} 这篇关于json帖子上有500个内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 21:02