1. 程式人生 > 其它 >P3355 騎士共存問題 題解

P3355 騎士共存問題 題解

測試步驟:

1.在首頁編寫一個提交的表單

<form action="/e/t1" method="post">
<input type="text" name="name">
<input type="submit">
</form>

 2.編寫對應處理類

 3.輸入中文測試:

解決:1.採用Get方式提交可解決

  2.編寫過濾器:

    <1 新建包filter,編寫EncodingFilter類繼承Filter

    

     < 2 在web.xml配置過濾器

      

         url-pattern寫/*,寫/無效

  3.採用SpringMVC自帶過濾器。直接在web.xml配置即可

<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>