spring mvc学习(9):路径参数

目录结构

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这个servlet起到分发的作用,对请求进行控制分发 --><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><!-- 每个springmvc项目都要一个springmvc项目配置位置,下面配置springmvc配置文件的路径 --><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/springMVC-servlet.xml</param-value></init-param><!-- 当容器启动时立即启动 --><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><!-- 下面配置springmvc的过滤分发请求类型,可以是/ 或者*.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 /><!-- 启动注解驱动 SpringMVC 功能 --><mvc:annotation-driven /><!-- 配置视图解析器 如何把handler 方法返回值解析为实际的物理视图 --><!--指定视图解析器--><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; // 这里导入了一个Model类
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;@Controller
@RequestMapping("/hi")
public class HiController {@RequestMapping("/say")public String say(Model model) { // 参数中传入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(){// System.out.println("执行登录");//System.out.println("username"+username);//System.out.println("password"+password);return "redirect:hi";}
}

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:参数直接获取");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>复制代码

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>

运行结果

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/424292.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql函数(五.流程控制函数)

流程控制函数 1.IF(expr1,expr2,expr3) 判断条件的正误&#xff0c;返回对应值 (1)判断条件的正返回expr2&#xff0c;否则返回expr3 select IF(10>5,大于,小于) as result; 结果&#xff1a;大于 2.IFNULL(expr1,expr2) 判断值是否为空 (1)判断值为空返回expr2&#x…

扩展String类

因为.Net Framework中的String类是封闭的&#xff0c;所以我们不能从它进行派生来扩展它的功能。 虽然String类已经提供了很多有用的方法来让我们进行字符串的处理和操作&#xff0c;但是有时候一些特殊的的要求还是不能能到满足。 一个例子就是&#xff1a;假如有一个因为句…

150 Evaluate Reverse Polish

1题目理解 输入&#xff1a;一个字符串数组。这个字符串数组表示算数运算的逆波兰表示法。一般算数表示方法是21&#xff0c;逆波兰表示是2 1 。 输出&#xff1a;一个int值。 Example 1: Input: [“2”, “1”, “”, “3”, “*”] Output: 9 Explanation: ((2 1) * 3) …

第八十七期:爬了知乎“沙雕问题”,笑死个人!

这两天偶然上网的时候&#xff0c;被知乎上一个名为“玉皇大帝住在平流层还是对流层”的问题吸引。 作者&#xff1a;数据森麟 这两天偶然上网的时候&#xff0c;被知乎上一个名为“玉皇大帝住在平流层还是对流层”的问题吸引。 图片来自 Pexels 本以为只是小打小闹&#xf…

django的url控制系统

无命名分组 &#xff08;\d{4}&#xff09; 有命名分组 &#xff08;&#xff1f;P<name>\d{4}&#xff09; 一个视图做两件事&#xff0c;提交方法不一样&#xff08;if 判断&#xff09; form action"/register/" django默认添加了当前面IP和端口 url别名…

641. Design Circular Deque

1 题目理解 要求设计一个双端循环队列。这个队列能支持以下操作&#xff1a; MyCircularDeque(k): Constructor, set the size of the deque to be k. insertFront(): Adds an item at the front of Deque. Return true if the operation is successful. insertLast(): Adds a…

QQ技术攻略-原来隐藏着这么多秘密(上)

一、将您的QQ的在线状态发布在互联网上将您的QQ的在线状态发布在互联网上&#xff0c;不用加好友也可以聊天.将您的QQ/TM的在线状态发布在互联网上&#xff1b;点击 QQ在线&#xff0c;不用加好友也可以聊天&#xff1b;寻找商机&#xff0c;广交朋友&#xff0c;"互动状态…

第八十八期:4000万程序员最爱开源项目和编程语言排名出炉!

今天&#xff0c;全球最大开发者社区GitHub重磅发布2019年度报告&#xff0c;透露了一个数据&#xff1a;GitHub目前在全球已有超过4000万开发者用户&#xff0c;其中80%来自美国之外的地区。 作者&#xff1a;小芹、亮亮 全球最大开发者社区GitHub今天重磅发布2019年度报告&…

Java2实用教程(第二版)程序代码——第十四章 Component类的常用方法

1//例子12import java.applet.*;import java.awt.*;3import java.awt.event.*;4import javax.swing.JTextArea;5publicclassExample14_1 extends Applet implements ItemListener6{ List list ; 7 JTextArea text; 8 public void init() 9 { listnew List(6,false…

239. Sliding Window Maximum

文章目录1理解题目2 思路2.1暴力求解2.2双端队列1理解题目 输入&#xff1a;整数数组nums&#xff0c;滑动窗口大小k 输出&#xff1a;整数数组 规则&#xff1a;在一个窗口内只能看到k个数&#xff0c;找一个最大的数&#xff0c;添加到返回数组中。每次滑动向右滑动一步。 …

第八十九期:还在手动盖楼领喵币?双十一这群开发者竟然如此「作弊」

开发者构建了一个脚本以自动逛双十一会场&#xff0c;让使用者轻松完成各种领币任务&#xff0c;同时还能解放双手。 作者&#xff1a;Synced 每年的 11 月份&#xff0c;总觉得有些硝烟弥漫。好在淘宝双十一领喵币&#xff0c;也已经有了自动化脚本。 感觉还未从去年双十一…

Serverless简介

说起当前最火的技术&#xff0c;除了最新的区块链&#xff0c;AI&#xff0c;还有一个不得不提的概念是Serverless。Serverless作为一种新型的互联网架构直接或间接推动了云计算的发展&#xff0c;从AWS Lambda到阿里云函数计算&#xff0c;Serverless一路高歌&#xff0c;同时…

使用matlab工具研究神经网络的简单过程(网络和数据下载)

本人在神经网络研究中是个新手的新手&#xff0c;使用matlab gui工具能够让我们这些小菜也可以研究这些复杂的问题。 在matlab中输入“nntool”&#xff0c;这样就可以出来gui了哈哈。然后按照提示输入&#xff1a;输入数据&#xff0c;目标数据&#xff0c;网络的设置。自然也…

第九十期:哪种人是软件设计中的稀缺型人才?

好的系统架构离不开好的接口设计&#xff0c;因此&#xff0c;真正懂接口设计的人往往是软件设计队伍中的稀缺型人才。 作者&#xff1a;从码农到工匠 好的系统架构离不开好的接口设计&#xff0c;因此&#xff0c;真正懂接口设计的人往往是软件设计队伍中的稀缺型人才。 为什…

151. Reverse Words in a String

1 题目理解 输入&#xff1a;一个字符串s 规则&#xff1a;一个单词是一串非空字符组成的。单词之间用空格分隔。 输出&#xff1a;将字符串按照单词反转字符串。多余的空格只保留一个。 Example 1: Input: s “the sky is blue” Output: “blue is sky the” Example 2: …

C语言输入字符和字符串

C语言有多个函数可以从键盘获得用户输入&#xff0c;它们分别是&#xff1a; scanf()&#xff1a;和 printf() 类似&#xff0c;scanf() 可以输入多种类型的数据。getchar()、getche()、getch()&#xff1a;这三个函数都用于输入单个字符。gets()&#xff1a;获取一行数据&…

收集一些正则表达式

匹配中文字符的正则表达式&#xff1a; [\u4e00-\u9fa5] 匹配双字节字符(包括汉字在内)&#xff1a;[^\x00-\xff] 应用&#xff1a;计算字符串的长度&#xff08;一个双字节字符长度计2&#xff0c;ASCII字符计1&#xff09; String.prototype.lenfunction(){return this.re…

第九十一期:架构设计常用到的10种设计模式,你都知道吗?

企业规模的软件系统该如何设计呢&#xff1f;在开始写代码之前&#xff0c;我们需要选择一个合适的架构&#xff0c;这个架构将决定软件实施过程中的功能属性和质量属性。因此&#xff0c;了解软件设计中的不同架构模式对我们的软件设计会有较大的帮助。 作者&#xff1a;abel_…

8. String to Integer (atoi)

1题目理解 输入&#xff1a;一个字符串s&#xff0c;可能包含空格、正负号、数字&#xff0c;还有其他字符。 输出&#xff1a;将字符串转为int 规则&#xff1a;字符串s一开始可能有很多空格&#xff0c;可以忽略这些空格&#xff0c;直到遇到第一个非空字符。从这个字符开始…

程序编码应保持良好的规范(C#)

呵呵&#xff0c;这个简直是超级老生常谈了。但我还是希望能让更多的程序员能了解一些细节习惯对于程序阅读性的影响。而这个很大程度决定了程序的可移植性。1。变量赋值之间注意保留空格。有些程序员往往不注意。不好的&#xff1a; Body.txtVersion.Textib.Version.ToString(…