把这里的只勾选这一行,Eclipse启动就快了。也不会有不该报错的报错。

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() +request.getContextPath()+"/";
%>
<!DOCTYPE html>
<html>
<head><base href="<%=basePath %>"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>new jsp</title>
</head>
<body><form action="<%=basePath %>logon2.htm" method=post><label>用户名:</label><input type="text" name="username"><br><label>密&nbsp;码:</label><input type="password" name="password"><br><label>年&nbsp;龄:</label><input type="text" name="age"><br><input type="submit" value="提交"></form>
</body>
</html>

FrontController.java

package cn.java.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;@Controller // 在一个普通类上一行加上@Controller就变成了Servlet了,就无需extends继承Servlet了。
public class FrontController {@RequestMapping(value="/login.html") //为当前方法配置一个对外访问的虚拟路径,@RequestMapping是springmvc框架特有的,并可以处理get和post请求public void Login() {System.out.println("登录成功");}//Servlet只能写一个方法,而用了springmvc可以写多个方法@RequestMapping(value= {"/register.htm","abc.html","hello.html"})  //可以配置很多个虚拟路径public void Register() {System.out.println("注册成功");}@RequestMapping(value= "/logon.htm") public void Logon(String username,String password) { //在进入地址http://localhost:8080/springMVC/logon.html?username=wang&password=123后得到的结果直接把username的值和password的值传到方法里去了,而Servlet是要用request来取值的,springmvc简单了很多System.out.println("用户名为" + username);System.out.println("密码为" + password);}@RequestMapping(value= "/logon2.htm",method=RequestMethod.POST) public String Logon2(User u) { //在进入地址http://localhost:8080/springMVC/logon2.html?username=wang&password=123后得到的结果直接把username的值和password的值传到类名为User中去了,User类中写好了username和password两个属性,还有setter getter方法,可以直接传进User对象中去,并且可以转好类型
        System.out.println(u);return "/success.jsp";}
}    

方法执行完跳转到其他页面:return "/success.jsp";

如果想用post传输方法,就在@RequestMapping里用method=RequestMethod.POST

这样就只支持post而不支持get了

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>springMVC</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><!-- 配置springMVC的核心控制器类:DispatcherServlet --><servlet><servlet-name>dispatcherServlet</servlet-name><!-- 按住ctrl + shift + H 输入DispatcherServlet,ok后在文件右键复制路径,粘贴到下面 --><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 将DispatcherServlet和springmvc.xml文件关联起来 --><init-param><param-name>contextConfigLocation</param-name><!-- param-value:给springmvc起一个文件名,固定写法,不能改 --><param-value>classpath:springmvc.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><!-- /*代表全部都拦截,/代表当前项目,*代表所有的,  如果是*.htm,那就拦截所有htm文件 --><url-pattern>*.htm</url-pattern></servlet-mapping>
</web-app>

转载于:https://www.cnblogs.com/lonske/p/9096683.html

SpringMVC_Controller注解与RequestMapping相关推荐

  1. Spring MVC 基础注解之@RequestMapping、@Controller、(二)

    我现在学的是spring4.2 今天主要学习了Spring MVC注解 引入注解可以减少我们的代码量,优化我们的代码. @Controller:用于标识是处理器类: @RequestMapping:请 ...

  2. springMVC注解中@RequestMapping中常用参数value params 以及@RequestParam 详解

    转载自 https://blog.csdn.net/qq_35067322/article/details/52811300?locationNum=9&fps=1 https://www.c ...

  3. requestmapping中path与value区别_1、Spring注解之@RequestMapping

    @RequestMapping是一个用来处理请求地址映射的注解,可用于类或者方法上.用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径. @RequestMapping注解有六个属性: 下面 ...

  4. SpringMVC框架 学习DAY_03:@RequestMapping注解/拦截器与过滤器

    1. 关于@RequestMapping注解 在控制器中,在处理请求的方法之前添加@RequestMapping注解,可以配置请求路径与处理请求的方法的映射关系! 在@RequestMapping注解 ...

  5. 【spring学习笔记】(二)Spring MVC注解配置 参数转换注解@RequestMapping@RequestParam、@PathVariable@MatrixVariable

    @TOC 介绍 在Spring MVC项目中,<\context:component-scan>配置标签还会开启@Request-Mapping.@GetMapping等映射注解功能(也就 ...

  6. RequestMapping注解的作用

    源码: @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented ...

  7. requestmapping注解访问404_开发人员都必须知道的Spring注解概览

    作者:飒然Hang 来源:rowkey.cn/blog 前言 从Java5.0开始,Java开始支持注解.Spring做为Java生态中的领军框架,从2.5版本后也开始支持注解.相比起之前使用xml来 ...

  8. Spring @RequestMapping注解示例

    在 spring mvc hello world 应用程序中,我们看到了具有端到端功能(不包括任何数据库访问)的非常基本的员工管理应用程序. 在学习spring mvc 模块的下一步中,我将提供@Re ...

  9. RequestMapping注解

    目录 1. @RequestMapping注解的功能 2. @RequestMapping注解的位置 3. @RequestMapping注解的value属性 4. @RequestMapping注解 ...

最新文章

  1. jQuery源码-jQuery.fn.each jQuery.each
  2. C++ 有符号整数和无符号整数修饰符之间的差别
  3. 关于Visual Studio 2019的前期详情
  4. C语言循环为1404的循环,考试,求大神帮忙,C语言,小弟感激不尽
  5. FastDFS(分布式文件系统)
  6. mogileFS分布式文件存储解决方案
  7. 输入框值不能赋值成功
  8. java学习笔记之斐波那契数列
  9. 20170702-变量说明,静态方法,类方法区别,断点调试,fork,yield协程,进程,动态添加属性等。。...
  10. 通用权限底层研究:强大的分页功能
  11. vue、react隐式实例化
  12. python实现mat格式数据解析处理,并转化为json格式数据
  13. Palindrome - URAL - 1297(求回文串)
  14. [问题记录]编译AArch64平台的sigar源码遇到的问题
  15. 求助,我在Kell官网上下载的固件库,双击运行后显示错误:Zip integrity check failed.,该怎么解决?
  16. Running Hero.
  17. Web前端助手-功能丰富的Chrome插件
  18. filebeat-logstash-es综合运用
  19. C--利用switch()浅浅做一个成绩等级划分小程序
  20. PVE安装ros系统

热门文章

  1. 如何将像素坐标转化为机械臂基座坐标_机械臂抓取自动精准标定
  2. 《Python入门到精通》函数
  3. dtoj#4179. 排行(rank)
  4. 面向切面的Spring
  5. WinFom中经典小游戏(含源码)
  6. ES6 学习笔记 (1)
  7. 使用Castle做类的增强
  8. 删除顽固文件的执行代码,删除rhsa属性文件,删除服务器中黑客留下...
  9. Linux中如何使用命令修改文件所属用户组
  10. phper需要掌握的技能(简)