Java

期末web作业收获

2020-06-11  本文已影响0人  GG_lyf

1.ssm接收put和delete请求,要在web.xml中写

    <!-- 4.使用rest风格的URI,将页面普通的post请求转为指定的delete或put请求 -->
    <!-- GET:查询; POST:新增; PUT:修改; DELETE:删除; 符合这种风格的http请求,我们就叫它RestFul风格 -->
    <filter>
        <filter-name>HiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>HiddenHttpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <!-- 将post请求转为put请求 -->
    <filter>
        <filter-name>HttpPutFormContentFilter</filter-name>
        <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>HttpPutFormContentFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

2.后端报错

WARN [http-nio-8080-exec-9] - Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized token 'cId': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'cId': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

要在前端阐述数据的地方加上 data:JSON.stringify(obj)

3.jsp页面跳转传值

//a页面
$(document).on("click",".clickIt",function() {
    var k = $(this).attr("value");//获取值
    console.log(k)
    var twoUrl = encodeURI("newsList.jsp?dddd="+k); //使用encodeURI编码  
    location.href = twoUrl;
});
//b页面
var twoText = window.location.href;
var twodata = twoText.split("="); //截取 url中的“=”,获得“=”后面的参数  
var twoText = decodeURI(twodata[1]); //decodeURI解码  
console.log(twoText)
``
上一篇 下一篇

猜你喜欢

热点阅读