日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

spring mvc学习(19):cookievalue注解(显示cookie的值,默认必须有值)

發(fā)布時(shí)間:2023/12/10 c/c++ 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring mvc学习(19):cookievalue注解(显示cookie的值,默认必须有值) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄結(jié)構(gòu)

web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>SpringMVC01</display-name><!-- 處理中文亂碼 --><filter><filter-name>encodingFilter</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>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- SpringMVC控制器 --><servlet><servlet-name>dispatcherServlet</servlet-name><!-- 主要就是DispatcherServlet這個(gè)servlet起到分發(fā)的作用,對請求進(jìn)行控制分發(fā) --><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><!-- 每個(gè)springmvc項(xiàng)目都要一個(gè)springmvc項(xiàng)目配置位置,下面配置springmvc配置文件的路徑 --><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/springMVC-servlet.xml</param-value></init-param><!-- 當(dāng)容器啟動(dòng)時(shí)立即啟動(dòng) --><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><!-- 下面配置springmvc的過濾分發(fā)請求類型,可以是/ 或者*.action等 --><url-pattern>/</url-pattern></servlet-mapping> </web-app>

springmvc-servlet

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"><!-- 定義要掃描 controller的包--><context:component-scan base-package="wormday.springmvc.helloworld" /><mvc:default-servlet-handler /><!-- 啟動(dòng)注解驅(qū)動(dòng) SpringMVC 功能 --><mvc:annotation-driven /><!-- 配置視圖解析器 如何把handler 方法返回值解析為實(shí)際的物理視圖 --><!--指定視圖解析器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 視圖的路徑 --><property name="prefix" value="/WEB-INF/"/><!-- 視圖名稱后綴 --><property name="suffix" value=".jsp"/></bean></beans>

HIcontroller類

package wormday.springmvc.helloworld;import org.springframework.stereotype.Controller; import org.springframework.ui.Model; // 這里導(dǎo)入了一個(gè)Model類 import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam;@Controller @RequestMapping("/hi") public class HiController {@RequestMapping("/say")public String say(Model model) { // 參數(shù)中傳入Modelmodel.addAttribute("name","wormday"); // 指定Model的值model.addAttribute("url","http://www.cnblogs.com/wormday/p/8435617.html"); // 指定Model的值return "say";}@RequestMapping("/loginForm")public String loginForm(){return "login";}@RequestMapping("/hi")public String loginFor(){return "hi";}@RequestMapping(value = "/login",method = RequestMethod.POST)public String loginXS(String username, String password){System.out.println("執(zhí)行登錄");System.out.println("username"+username);System.out.println("password"+password);return "redirect:hi";}@RequestMapping("/testcase")public String testCookie(@CookieValue("JSESSIONID") String sessionId){System.out.println(sessionId);return "success";} }

usercontroller類

package wormday.springmvc.helloworld;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam;@Controller @RequestMapping("/hi") //@RequestMapping("/list")public class UserController {/* @RequestMapping(value = "/list",method = RequestMethod.GET)public String login(String username,String password){System.out.println("方法1:參數(shù)直接獲取");System.out.println("username:"+username);System.out.println("password:"+password);return "list";}*/@RequestMapping(value = "/list",method = RequestMethod.GET)public String listForm(@RequestParam(value = "currentpage",required = false,defaultValue = "1")Integer currentpage,@RequestParam(value = "pagesize",required = false,defaultValue = "10")Integer pagesize){System.out.println("currentpage"+currentpage);System.out.println("pagesize"+pagesize);return "list";} }

say.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body> hello world,${name} <br/>${url}</body> </html>復(fù)制代碼

login.jsp

<%--Created by IntelliJ IDEA.User: geyaoDate: 2019/11/6Time: 19:57To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body> <form action="hi" method="post"><label for="username">用戶名<input type="text" id="username" name="username"></label><label for="password">密碼<input type="text" id="password" name="password"></label><button>登錄</button> </form> </body> </html>

hi.jsp

<%--Created by IntelliJ IDEA.User: geyaoDate: 2019/11/6Time: 20:17To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body> 我是歌謠,登錄成功 </body> </html>

list.jsp

<%--Created by IntelliJ IDEA.User: geyaoDate: 2019/11/6Time: 19:57To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body> <h1>我是表單</h1></body> </html>

success.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body> 成功</body> </html>

運(yùn)行結(jié)果

?

總結(jié)

以上是生活随笔為你收集整理的spring mvc学习(19):cookievalue注解(显示cookie的值,默认必须有值)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。