SpringMVC 登录DEMO
2014-08-29 16:56
197 查看
引言:最近工作上接触到了Spring的mvc,之前没有接触过,感觉很陌生。今天有点闲就在网上找了点资料学习了,也算是成功了吧!之前一直都在用Struts2的mvc,相比之下,我更喜欢用Spring的mvc。总之各有各的优点吧!看看各位怎么用了。
下面是我基于Spring MVC写的一个简单的登录demo。
工程一览图:
下面简单的看下具体的代码:
web.xml:
至于jsp里面的代码就不展示了,感兴趣的可以直接去下载案例,里面的Spring的包都齐全,可以直接运行的,但愿对像我一样的初学者有所帮助!
demo地址:http://download.csdn.net/detail/javaweiming/7839841
下面是我基于Spring MVC写的一个简单的登录demo。
工程一览图:
下面简单的看下具体的代码:
web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <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> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern><!-- 意思是拦截所有请求 --> </servlet-mapping> </web-app>springMVC-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" 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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd "> <mvc:annotation-driven /> <!-- 注释资源扫描包路径 --> <context:component-scan base-package="com.controllers" /> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- 配置视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"/> <property name="suffix" value=".jsp"/> </bean> </beans>TestController:
package com.controllers; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.models.Student; @Controller @RequestMapping("/test") public class TestController { @RequestMapping(value = "/test") public String test(HttpServletRequest request) { Student s = new Student(); System.out.println("name===" + s.getName()); System.out.println("password===" + s.getPassword()); String userName = request.getParameter("userName"); String userPwd = request.getParameter("userPwd"); request.setAttribute("userName", userName); if (s.getName().equals(userName) && s.getPassword().equals(userPwd)) { return "success"; } return "fail"; } }
至于jsp里面的代码就不展示了,感兴趣的可以直接去下载案例,里面的Spring的包都齐全,可以直接运行的,但愿对像我一样的初学者有所帮助!
demo地址:http://download.csdn.net/detail/javaweiming/7839841
相关文章推荐
- springMVC 简单的登录demo
- SpringMVCDemo-登录小例子
- 一个SpringMVC demo
- 小程序的支付Demo和登录Demo
- [java web基础]实现自动登录功能demo
- Shiro 整合SpringMVC 并且实现权限管理,登录和注销
- SpringMVC 拦截器实现原理和登录实现
- sharedperferences 记住密码,自动登录demo
- springMVC使用ehcache实现简单的单点登录
- android loginDemo +WebService用户登录验证
- springmvc+shiro用户登录后获取用户
- android loginDemo +WebService用户登录验证 续篇
- Spring MVC +MyBatis +MySQL 登录查询Demo 解决了mybatis异常【转】
- Android 登录demo
- jQuery登录增删改查小demo
- springmvc用户未登录自定义拦截器
- 11 Spring MVC 访问入参获取和拦截器使用(@RequestParam 和 Interceptors)登录模块demo
- springmvc控制登录用户session失效后跳转登录页面
- 封装高可复用的服务端响应对象和登录demo
- Joomla(5)登录、注销、注册和更新的Demo