無法進(jìn)入$.get(seckill.URL.now(),{}, function(result){。。。},報(bào)404錯(cuò)誤
瀏覽器可以正常請求到j(luò)son數(shù)據(jù),但是$.get('/seckill/time/now',{},function(result){...}無法獲得json數(shù)據(jù),報(bào)404錯(cuò)誤
瀏覽器http請求頭和響應(yīng)頭:
Accept
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8????
Accept-Encoding????gzip,?deflate????
Accept-Language????zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3????
Cache-Control????max-age=0????
Connection????keep-alive????
Cookie????JSESSIONID=06FAA701426C4EC382C2E7F11F88779C????
DNT????1????
Host????localhost:8083????
Upgrade-Insecure-Requests????1????
User-Agent????Mozilla/5.0?(Windows?NT?6.2;?WOW64;?rv:53.0)?Gecko/20100101?Firefox/53.0
Content-Typeapplication/json;charset=UTF-8 ? ?
Date ? ?Tue, 09 May 2017 13:40:32 GMT ? ?
Server ? ?Apache-Coyote/1.1 ? ?
Transfer-Encoding ? ?chunked ? ?
$.get()的請求頭和響應(yīng)頭:
GET? http://localhost:8083/seckill/time/now
Host: localhost:8083
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest????? //網(wǎng)上查說這里不一樣,但不造怎么處理
Referer: http://localhost:8083/seckill-alpha/seckill/1009/detail
Cookie: killPhone=13812345678
DNT: 1
Connection: keep-alive
Server:?Apache-Coyote/1.1
Content-Type:?text/html;charset=utf-8
Content-Language:?en
Content-Length:?983
Date:?Tue,?09?May?2017?13:41:05?GMT
Controller:
????@RequestMapping(value?=?"/time/now",?method?=?{RequestMethod.GET,RequestMethod.POST}, ????????????produces?=?{"application/json;charset=UTF-8"}) ????@ResponseBody ????public??SeckillResult<Long>?time(){ ????????Date?now?=?new?Date(System.currentTimeMillis()); ????????logger.info("/time/now=====??",?now); ????????System.out.println("/time/now=====??"+now); ????????SeckillResult<Long>?result?=?new?SeckillResult<Long>(true,?now.getTime()); ????????return?result;?????? ????}
web.xml
<?xml?version="1.0"?encoding="UTF-8"?> <web-app?xmlns="http://xmlns.jcp.org/xml/ns/javaee" ??xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ??xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee ??????????????????????http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" ??version="3.1" ??metadata-complete="true"> <display-name>secikill-webapp</display-name> <!--修改servlet版本為3.1--> <!--配置DispatcherServlet--> <context-param> ????????<param-name>contextConfigLocation</param-name> ????????<param-value>classpath:spring/spring-*.xml</param-value> </context-param> <servlet> ????<servlet-name>servlet-dispatcher</servlet-name> ????<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> ????<!--配置springmvc需要加載的配置文件 ????????spring-dao.xml,spring-service.xml,?spring-web.xml ????????shunxumybatis->spring->springmvc ????--> ????<init-param> ????????<param-name>contextConfigLocation</param-name> ????????<param-value>classpath:*spring/spring-*.xml</param-value> ????</init-param> ????????<load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> ????<servlet-name>servlet-dispatcher</servlet-name> ????<!--默認(rèn)匹配所有請求,注意靜態(tài)資源--> ????<url-pattern>/</url-pattern> </servlet-mapping> ????<welcome-file-list> ????????<welcome-file>/index.jsp</welcome-file> ????</welcome-file-list> ????<!--?配置SESSION超時(shí),單位是分鐘?--> ????<session-config> ????????<session-timeout>15</session-timeout> ????</session-config> ??<!--???編碼過濾器?--> ????<filter> ????????<filter-name>encodingFilter</filter-name> ????????<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> ????????<async-supported>true</async-supported> ????????<init-param> ????????????<param-name>encoding</param-name> ????????????<param-value>UTF-8</param-value> ????????</init-param> ????</filter> <!--?????<filter-mapping> ????????<filter-name>encodingFilter</filter-name> ????????<url-pattern>/*</url-pattern> ????</filter-mapping>?--> ????<!--?Spring監(jiān)聽器?--> ????<listener> ????????<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> ????</listener> ????<!--?防止Spring內(nèi)存溢出監(jiān)聽器?--> ????<listener> ????????<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> ????</listener> ???? </web-app>
2017-05-20
$.get('/seckill/time/now',{},function(result)
==》$.get('/seckill-alpha/seckill/time/now',{},function(result);
把項(xiàng)目名加上去試試..
2019-04-16
或者這樣寫也可以的:
我們把URL里的返回路徑統(tǒng)一設(shè)置一下就可以啦。同理,這里的/shopping是我的tomcat服務(wù)器的部署路徑。
2019-04-15