新建一个登陆页面:loginActionSupport.jsp,代码例如以下

 





<%@page contentType="text/html;charset=GBK" isELIgnored="false"%>

 

<html>

 

<head><title>;实现用户登录实例,struts和Spring整合</title></head>

 

<body>





spring

<font size=’22’> $<br> </font> 

<form name="form1" action="/myLogin/loginActionSupportdo" method="post">

 

用户名:<input type="text" name="username" value="${user.username}"/><br>

 

密码:<input type="password" name="password" value="${user.password}"/><br>

 

<input type="submit" name=”method” value="提交"/>

 

</form>

 

</body>

 

</html>

 

创建一个存储登陆用户信息的类:User.java该类继承于ActionForm,代码例如以下:

 





package com.zhaosoft.bean;

 

import org.apache.struts.action.ActionForm;

 

public class User extends ActionForm{

 

private String username=null;

 

private String password=null;

 

public String getUsername() {

 

return username;

 

}

 

public void setUsername(String username) {

 

this.username = username;

 

}

 

public String getPassword() {

 

return password;





spring



public void setPassword(String password) {

 

this.password = password;

 

}

 

}

 

Com.zhaosoft.action中新建一个LoginActionSupport.java,该类不继承于struts的Action,而是继承于Spring的ActionSupport,代码示比例如以下:

 





package com.zhaosoft.action;

 

import javax.servlet.http.HttpServletRequest;

 

import javax.servlet.http.HttpServletResponse;

 

import org.apache.struts.action.ActionForm;

 

import org.apache.struts.action.ActionForward;

 

import org.apache.struts.action.ActionMapping;

 

import org.springframework.context.ApplicationContext;

 

import org.springframework.web.struts.ActionSupport;

 

import com.zhaosoft.bean.User;





spring

import com.zhaosoft.domain.Login; 

public class LoginActionSupport extends ActionSupport {

 

public ActionForward execute(ActionMapping mapping,ActionFormform,

 

HttpServletRequest request,HttpServletResponse response)

 

throws Exception {

 

// 通过ApplicationContext获取配置文件

 

ApplicationContext ctx = getWebApplicationContext();

 

Login login = (Login) ctx.getBean("login");

 

login.login((User) form);





spring

request.setAttribute("msg",login.getMsg()); 

request.setAttribute("user",(User) form);

 

return mapping.findForward("login");

 

}

 

}

spring应用实例的更多相关文章

  1. spring得到实例和new一个实例,哪个快?

    spring配置的bean是默认单例,那么在程序中,得到一个实例一定比创建一个实例的速度快,也更加省资源.今天实际测试的时候发现,new 一个对象比spring得到一个对象快多了.后面自己又加了个单例 ...

  2. Spring Security4实例(Java config版)——ajax登录,自定义验证

    本文源码请看这里 相关文章: Spring Security4实例(Java config 版) -- Remember-Me 首先添加起步依赖(如果不是springboot项目,自行切换为Sprin ...

  3. Spring Security4实例(Java config 版) —— Remember-Me

    本文源码请看这里 相关文章: Spring Security4实例(Java config版)--ajax登录,自定义验证 Spring Security提供了两种remember-me的实现,一种是 ...

  4. Spring Aop实例@Aspect、@Before、@AfterReturning@Around 注解方式配置

    用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...

  5. SSH---整合Struts2&Spring&Hibernate(实例)

    一.SSH回顾 Struts2:核心为过滤器+拦截器.过程:Filter--->FilterDispatcher-->ActionMapper-->ActionProxy--> ...

  6. Spring事物实例

    Spring事务实例: entity实体类: public class Accounts { private int accountid; private String accountname; pr ...

  7. Spring登录实例

    Spring登录实例 项目结构 首先看一下整个项目的目录结构,如下: 导入Jar包 工欲善必先利其器,导入一下Jar包 配置文件 web.xml 配置 web.xml配置文件,如下: xmlns:xs ...

  8. Spring AOP实例——异常处理和记录程序执行时间

    实例简介: 这个实例主要用于在一个系统的所有方法执行过程中出线异常时,把异常信息都记录下来,另外记录每个方法的执行时间. 用两个业务逻辑来说明上述功能,这两个业务逻辑首先使用Spring AOP的自动 ...

  9. [Spring框架]Spring开发实例: XML+注解.

    前言: 本文为自己学习Spring记录所用, 文章内容包括Spring的概述已经简单开发, 主要涉及IOC相关知识, 希望能够对新入门Spring的同学有帮助, 也希望大家一起讨论相关的知识. 一. ...

  10. Redis+Spring缓存实例

    转自:小宝鸽 一.Redis了解 1.1.Redis介绍: redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).lis ...

随机推荐

  1. TreeView控件的展开与折叠

    在窗体中添加一个TreeView控件,设置CheckBox属性为True,绑定数据 Archive jkj = new Archive();//自定义类        public void Bind ...

  2. 又在折腾cygwin

    apt-cyg https://github.com/transcode-open/apt-cyg/blob/master/README.md cygwin 163镜像 http://mirrors. ...

  3. openCV 和GDI画线效率对比

    一. 由于项目需要,原来用GDI做的画线的功能,新的项目中考虑到垮平台的问题,打算用openCV来实现,故此做个效率对比. 二. 2点做一条线,来测试效率. 用了同样的画板大小---256*256的大 ...

  4. Python爬虫之路——简单的网页抓图

    转载自我自己的博客:http://www.mylonly.com/archives/1401.html 用Python的urllib2库和HTMLParser库写了一个简单的抓图脚本.主要抓的是htt ...

  5. 服务器负载均衡lvs(Linux Virtual Server)

    服务器负载均衡lvs(Linux Virtual Server) 一.总结 LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统. 三.Linu ...

  6. 使用ionic3快速开发webapp(一)

    Ionic可以让我们使用web技术快速构建接近原生体验的跨平台移动应用. 一.安装ionic 1.需要先安装 Node.js(版本8.x之上): 2.安装cordova 和 ionic: $ npm ...

  7. iOS开发webView的使用二

    #import "ViewController.h" @interface ViewController ()<UIWebViewDelegate> @property ...

  8. Json入门 分类: C_OHTERS 2014-04-23 16:20 601人阅读 评论(0) 收藏

    参考<疯狂android讲义>>730页 JSON的基础请参考W3SCHOOL的教程: http://www.w3school.com.cn/json/index.asp 例子: h ...

  9. URIEncoding

    http://thoughtfly.iteye.com/blog/1533481 http://docs.spring.io/spring/docs/current/spring-framework- ...

  10. 浅谈struts2的国际化----i18n

    可能大家在使用struts框架的时候,偶尔会看到这个词: i18n.也就是 Internationalization    i 开头,n 结尾. 总共18个字母,今天的主要内容就是环绕这 四个字母. ...