- 浏览: 5100198 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
silence19841230:
先拿走看看
SpringBoot2.0开发WebSocket应用完整示例 -
wallimn:
masuweng 写道发下源码下载地址吧!三个相关文件打了个包 ...
SpringBoot2.0开发WebSocket应用完整示例 -
masuweng:
发下源码下载地址吧!
SpringBoot2.0开发WebSocket应用完整示例 -
masuweng:
SpringBoot2.0开发WebSocket应用完整示例 -
wallimn:
水淼火 写道你好,我使用以后,图标不显示,应该怎么引用呢,谢谢 ...
前端框架iviewui使用示例之菜单+多Tab页布局
作者:http://wallimn.iteye.com,时间:2016-02-15
一个很简单的SpringMVC示例,注意,很简单,仅具演示作用。
用eclipse建立一个dynamic web project,加入相应包,Servlet的版本使用3.0,比较简单,不过多介绍。项目的文件结构如下图所示:
下面介绍一下文件内容。
1. web.xml
主要是配置了Spring的Servlet,指定其处理*.do的请求,注意Servlet的名称为spring,收到相应的请求后,会使用[ServletName]-servlet.xml解析对应的请求,也就是sping-servlet.xml。还配置了一个过滤器,解决中文乱码问题。
2. spring-servlet.xml
3. user/show.jsp
显示用户的信息
4. user/register.jsp
用户注册信息输入页面
4. UserController.java
5. index.jsp
欢迎页面,显示两个链接,方便查看效果
一个很简单的SpringMVC示例,注意,很简单,仅具演示作用。
用eclipse建立一个dynamic web project,加入相应包,Servlet的版本使用3.0,比较简单,不过多介绍。项目的文件结构如下图所示:
下面介绍一下文件内容。
1. web.xml
主要是配置了Spring的Servlet,指定其处理*.do的请求,注意Servlet的名称为spring,收到相应的请求后,会使用[ServletName]-servlet.xml解析对应的请求,也就是sping-servlet.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> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
2. spring-servlet.xml
<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.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 这个包里的所有Controller都扫描 --> <context:component-scan base-package="com.wallimn.controller" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/view/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
3. user/show.jsp
显示用户的信息
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>显示用户信息</title> </head> <body> <h3 style="text-align:center;border-bottom:1px solid gray;">用户信息</h3> <div style="text-align:center"> 用户ID:${user.id } <br> 用户名:${user.name} <br> 密 码:${user.password} </div> </body> </html>
4. user/register.jsp
用户注册信息输入页面
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>显示用户信息</title> </head> <body> <h3 style="text-align:center;border-bottom:1px solid gray;">用户注册</h3> <div style="text-align:center"> <form action="register.do" method="post"> 用户名:<input type="text" name="name"> <br> 密 码:<input type="password" name="password"> <br> <input type="submit" value="提交"> </form> </div> </body> </html>
4. UserController.java
package com.wallimn.controller; import java.util.HashMap; import java.util.Map; import java.util.UUID; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/user") /** * * @author http://wallimn.iteye.com * */ public class UserController { /** * 显示指定的用户信息 * @param userId * @return */ @RequestMapping("/show/{userId}") public ModelAndView show(@PathVariable String userId){ Map<String,Object> user = new HashMap<String,Object>(); user.put("id", userId); user.put("name", "wallimn"); user.put("password", "password"); return new ModelAndView("user/show","user",user); } /** * 显示用户注册界面 * @param name * @param password * @return */ @RequestMapping(value="/register",method = RequestMethod.GET) public String register_get(String name,String password){ return "user/register"; } /** * 用户注册处理 * @param name * @param password * @return */ @RequestMapping(value="/register",method = RequestMethod.POST) public ModelAndView register_post(String name,String password){ Map<String,Object> user = new HashMap<String,Object>(); user.put("id", UUID.randomUUID().toString()); user.put("name", name); user.put("password", password); return new ModelAndView("user/show","user",user); } }
5. index.jsp
欢迎页面,显示两个链接,方便查看效果
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>SpringMVC首页</title> </head> <body> <h3 style="text-align:center;border-bottom:1px solid gray;">请点击以下链接</h3> <div style="text-align:center"> <a href="user/show/1.do">查看用户信息</a> <a href="user/register.do">用户注册</a> </div> </body> </html>
发表评论
-
gradle编译错误:Could not find method compile() for arguments
2020-09-19 10:50 18184编译(IDEA+Gradle)一个别人的工程,出现一个 ... -
netty心跳检查之UDP篇
2019-09-15 08:50 2120部分UDP通信场景中,需要客户端定期发送心跳信息,以获取终 ... -
解决tomcat部署两个SpringBoot应用提示InstanceAlreadyExistsException
2019-06-30 11:49 3167两个SpringBoot应用部署在一个Tomcat中,单独 ... -
Eclipse配置MyBatis代码自动化功能
2019-06-29 10:16 16401.安装插件 Eclipse中,Help->Ecli ... -
vue.js中使用qrcode生成二维码
2019-05-20 00:00 7559一、安装包 npm install qrcodejs2 --s ... -
MySQL插入数据报错: Incorrect string value: '\xFD\xDE'
2019-03-31 23:19 1171我MySQL数据库用的uft-8字符集,插入数据一直很正常 ... -
vue自定义组件并双向绑定属性
2019-03-08 22:46 3207做了两个子组件,原理基本一样,一个是使用原生的select ... -
vue-router简单示例
2019-03-05 00:32 1086写个基本完整、稍有借鉴意义的示例,防止自己忘记。 &l ... -
“联通充值系统繁忙”轻松应对
2019-02-06 11:03 3904大过年的,联通充个值一直报“充值系统繁忙”。昨天晚上试了几 ... -
electron.js数据库应用---导航菜单(element-ui+mysql)
2019-02-05 21:33 2296一、环境搭建 略, ... -
electron.js数据库应用---入门(mysql+element-ui)
2019-01-27 23:19 7304我的机器:Windows10,64 ... -
SpringMVC 在controller层中注入成员变量request,是否线程安全
2018-12-17 21:17 2690@RestController public class ... -
VueJS 组件参数名命名与组件属性转化
2018-12-03 00:00 2003转自:https://www.cnblogs.com/meiy ... -
vue-resource拦截器实现token发送及检验自动化
2018-11-16 22:38 3039用了很长时间vue-resource,最近思考$http发 ... -
element-ui试用手记
2018-10-29 20:25 1684element-ui、iviewui都以vue.js为基础 ... -
iviewui中表格控件中render的使用示例
2018-07-07 16:46 9711示例了如何在表格中显示按钮,如何将代码转化为文字。 i ... -
Tomcat错误“Alias name tomcat does not identify a key entry”解决
2018-07-05 21:39 6173申请到了阿里云的证书后,下载、按照说明生成jks格式证书、 ... -
阿里云免费证书“fileauth.txt内容配置错误”解决
2018-07-05 20:43 5193最近研究微信小程序开发,上阿里云申请了个证书,使用文件验证 ... -
springboot2.0跨域配置
2018-07-04 22:11 5234springboot2.0跨域配置: 一、代码 ... -
微信小程序使用code换openid的方法(JAVA、SpringBoot)
2018-07-01 21:52 10293微信小程序序的代码中提示,使用code换取openid,但 ...
相关推荐
springmvc测试入门示例,下载即可运行
极客学院java中级课程,SpringMVC系列教材——快速入门
Maven+SpringMVC的入门级HelloWorld实例,简单了解Maven和SpringMVC整合
springmvc 基于注解的入门实例,仅适合初学者参考!
spring mvc入门示例
SpringMVC+myBatis入门简单示例分享,轻量级 SpringMVC+myBatis入门简单示例分享,轻量级 SpringMVC+myBatis入门简单示例分享,轻量级 适合新手学习
springmvc_demo_02是非注解模式,springmvc_demo_03是手动指定springmvc的核心配置文件的位置的,springmvc_demo_04是使用springMVC的注解模式 csdn原文博客:...
SpringMVC入门示例教程,简单基础。适和SpringMVC初级学习者
Tiles框架入门教程示例(含Springmvc),简单的springmvc整合tiles框架,maven管理
第一个springMVC示例+源码,仅供入门.
java spring mvc超简单示例,适合入门
SpringMvc 简单例子,入门级教程,你值得拥有。容易上手。
对于新手,应该怎么去学习这门框架技术呢,应广大技术朋友的反应,我编写了此套教程,帮助新手朋友们更加快速的上手SpringMVC,希望朋友们喜欢。谢谢大家。 教程内含:源码,步骤,示例,知识点讲解,图文并茂。无论...
包含springMVC3.1的所有jar包,springmvc环境搭建及入门的例子,helloword,
java源码 maven+springmvc+mybatis+log4j 入门级示例 .
这篇文章将教你快速地上手使用 Spring 框架. 如果你手上有一本《Spring in Action》, 那么你最好从第三部分"Spring 在 Web 层的应用--建立 Web 层"开始看, 否则那将是一场恶梦! 首先, 我需要在你心里建立起 Spring...
Spring-mvc spring ,mvc 适合入门
SSM spring + springMVC +myBatis 非maven 源代码 ,再详细不过的,简单入门的 ssm 框架 SSM SSM源代码 SSM SSM源代码