TestController的代码,如下所示
package shirospringweb.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class TestController{ @RequestMapping("/test") public String testPage(){ return "WEB-INF/pages/test.html"; } }对应前端页面,如下所示(别看他挺多的样子其实啥也没有,这里主要是将了一个在springmvc页面中也是中文的配置,可以当做没看见)
<html> <head> <title>TestPage</title> </head> <body> TestPage, <br/> This Page only display English character. <br /> To display chineses character, you should add an encoding filter in web.xml, like this <br /> <br /> <br /> <filter><br /> <filter-name>encodingFilter</filter-name><br /> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><br /> <init-param><br /> <param-name>encoding</param-name><br /> <param-value>UTF-8</param-value><br /> </init-param><br /> <init-param><br /> <param-name>forceEncoding</param-name><br /> <param-value>true</param-value><br /> </init-param><br /> </filter><br /> <filter-mapping><br /> <filter-name>encodingFilter</filter-name><br /> <url-pattern>/*</url-pattern><br /> </filter-mapping><br /> </body> </html>3.2 Test2Controller 及其页面
Test2Controller的代码
package shirospringweb.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class Test2Controller { @RequestMapping("/test2") public String getTest2Page(){ return "WEB-INF/pages/test2.html"; } }其对应的界面如下:
<html> <head> Test 2 Page </head> <body> This is the test 2 page <br/> (Can not display chinese Character, more information <a href="http://www.likecs.com/app/test">click here</a>) </body> </html>3.3 LoginController 及其对应的界面
LoginController的代码
package shirospringweb.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class LoginController { @RequestMapping("/login") public String getLogin(){ return "WEB-INF/pages/login.html"; } }其对应的登录界面
<html> <head>Login Page</head> <body> This is Login Page With No Chinese Character <br> <form action="/app/login" method="POST"> username : <input /><br/> password : <input /><br/> <input type="submit" value="LOGIN"/> </form> </body> </html>好了,代码到这儿完事儿了,下面是运行的效果图
(4).运行效果4.1 首先访问/app/test页面可以访问到(shiro未拦截)
页面如下
4.2 其实访问/app/test2需要登录,登录后需要后跳转(可能需要访问两次,有一次请求URL会带参数,这个shiro会报错,这是shiro的问题,可以百度解决)具体如下:
登录后跳转
访问/logout会退出到主页面,这个就不截图了