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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:config/springMVCAnnotation-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<!-- 前端控制器的配置 自此请求已经交个spring web mvc框架处理 然后配置spring -->

springMVCAnnotation-servlet.xml文件

  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

<!-- 注解扫苗包 -->
<context:component-scan base-package="com.tgb.web.controller.annotation" />
<!-- 开启注解 -->
<mvc:annotation-driven/>
<!-- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>

</beans>

addUser.jsp文件

   

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
<title>My JSP 'addUser.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<script type="text/javascript">
function addUser() {
var form = document.forms[0];
form.action="/springMVC8/user/data/addUser";
form.method="get";
form.submit();
}
</script>

</head>

<body>

<h>添加用户</h>
<form action="" method="get">
姓名:<input type="text" name="userName">
年龄:<input type="text" name="age">

<input type ="button" value="添加" onClick=addUser()>

</form>
</body>
</html>

userManager.jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'userManager.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<h1>用户管理</h1>
姓名:=====${userName }
<br/>
年龄:=====${age }
</body>
</html>

 

springMVC参数传递的更多相关文章

  1. 使用SpringMVC参数传递时,解决get请求时中文乱码的问题

    问题描述: 使用SpringMVC参数传递时, 遇到get请求中文信息时,页面应答会显示中文乱码. 解决办法: 一,  我们需要把request.getParameter(“参数名”)获取到的字符串先 ...

  2. SpringMVC参数传递方案

    SpringMVC参数传递方案 登录 @PostMapping("/login") @ResponseBody public Map login(String username, ...

  3. SpringMVC参数传递 HttpServletRequest,HttpServletResponse和HttpSession

    SpringMVC参数传递 HttpServletRequest,HttpServletResponse和HttpSession 2017-11-27 16:44:51 douunderstand 阅 ...

  4. 8.SpringMVC参数传递

    页面参数传递到controller, 可被同名(与页面标签上的name名对应)的参数接收,用request设值,页面再取出来. 注意乱码解决办法: ①如果是get提交,则在tomcat的server. ...

  5. SpringMvc参数传递中乱码问题

    问题描述: 当传递中文参数到controller类时,无乱是get方式还是post方式都出现乱码 解决: 1.保证所有的页面编码都是utf-8,包括jsp页面,浏览器编码设置和eclipse的编码设置 ...

  6. springMvc参数传递的方法

    package cn.edu.hj.controller; import java.util.Map; import javax.servlet.http.HttpServletRequest; im ...

  7. SpringMVC——参数传递

    一.接收零散参数 1.装配原则为传递参数名和方法接收参数名一致 2.手动装配@RequestParam  name代表页面发送的参数名字  required代表参数是否必须传递  false代表可以不 ...

  8. SpringMVC 参数传递

    使用@RequestParam 注解获取GET请求或POST请求提交的参数: 获取Cookie的值:使用@CookieValue : 根据不同的Web请求方法,映射到不同的处理方法:使用登陆页面作示例 ...

  9. SpringMVC 参数传递和接收的几种方式

    普通传参 测试项目:SpringBoot2.0.不使用 form 表单传参,后端不需要指定 consumes . 使用 Postman 进行测试. @PathVariable 只能接收 URL 路径里 ...

随机推荐

  1. Fatal error in launcher: Unable to create process using '"'

    今天遇到了 Fatal error in launcher: Unable to create process using '"' 这个问题,原来是我上次装python3.5的时候,pyth ...

  2. MongoDB 知识要点一览

    1.启动mongoDb数据库: 进入mongoDB的安装目录,执行如下命令 C:\Program Files\MongoDB\Server\3.0\bin>mongod.exe --dbpath ...

  3. Python 第一个Python项目Hello,Python 学习之路(二)

    print("Hello,Python")

  4. [Note] changing building platform from vs 2013 to vs community 2015

    The error turned out as "undefined linkage"(The same as you haven't use some function that ...

  5. TSuperEnumerator、TSuperAvlIterator、ObjectFindFirst

    通过 ISuperObject.GetEnumerator 可获取一个 TSuperEnumerator 对象. TSuperEnumerator 主要有: MoveNext 方法.Current 属 ...

  6. 《CODE》书摘

    2016-11-08 14:59:16 可以说英语词汇就是一种编码. 2016-11-08 15:19:04 实际上任何两种不同的东西经过一定的组合都可以代表任何种类的信息. 2016-11-08 1 ...

  7. 多个网站使用不同的SSH密钥登陆(zz)

    多个网站使用不同的SSH密钥登陆   1.创建不同的SSH密钥, -t指定加密方法,RSA或DSA:-C注释:-f指定文件名   www.2cto.com   ssh-keygen -t dsa -C ...

  8. 读书笔记——body and html

    在看<常见标签的默认属性值及相互作用——关于CSS reset的思考>的时候,其中说body默认的margin是8px.但是,将body的backgound-color:red:后,看到的 ...

  9. (python)图片处理Pillow模块的使用

    Pillow中最重要的类就是Image,该类存在于同名的模块中.可以通过以下几种方式实例化:从文件中读取图片,处理其他图片得到,或者直接创建一个图片. 还有一个类为ImageDraw,用来画图. 1. ...

  10. EXCEL的导入导出

    using System; using System.Data; using System.Data.OleDb; using System.IO; namespace COMMON { public ...