如題,最近以spring mvc作為后臺(tái)框架,前端異步獲取數(shù)據(jù)時(shí)(.html為后綴名的訪問方式),報(bào)406 Not Acceptable錯(cuò)誤。當(dāng)初都不知道啥原因,前后臺(tái)都沒報(bào)錯(cuò)就是返回不了數(shù)據(jù),于是查了下http 406響應(yīng)碼:406 (SC_NOT_ACCEPTABLE)表示請(qǐng)求資源的MIME類型與客戶端中Accept頭信息中指定的類型不一致。下面請(qǐng)看出錯(cuò)的操作流程及代碼:

1、先配置spring mvc 核心servlet (DispatcherServlet) 至web.xml中,其中配置可以以.html和.do為后綴名的請(qǐng)求。(注意:只顯示重要代碼,下面也是一樣)

平面設(shè)計(jì)培訓(xùn),網(wǎng)頁設(shè)計(jì)培訓(xùn),美工培訓(xùn),游戲開發(fā),動(dòng)畫培訓(xùn)

    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:dispatcher-servlet.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>DispatcherServlet&l
        
		

網(wǎng)友評(píng)論