ITPub博客

首页 > 应用开发 > IT综合 > struts2 与spring 相结合做出的登陆实例

struts2 与spring 相结合做出的登陆实例

原创 IT综合 作者:terryisme 时间:2009-03-05 14:18:37 0 删除 编辑
原代码如下:
LoginService.java
package org.test.service;
public interface LoginService {
public boolean isLogin(String username,String password);
}

LoginServiceImpl .java

package org.test.service.impl;

import org.test.service.LoginService;

public class LoginServiceImpl implements LoginService {

public boolean isLogin(String username, String password) {
//判断用户所以输入的数据是否为gao,qin,如果是则登陆成功,否则失败
// TODO Auto-generated method stub
if(username.equals("gao") && password.equals("qin")){
return true;
}
return false;
}

}

LoginAction.java

package org.test.struts2Action;

import org.test.service.LoginService;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class LoginAction extends ActionSupport {
private String username;
private String password;
@SuppressWarnings("unused")
private LoginService loginService;
@Override
public String execute() throws Exception {
if(loginService.isLogin(username, password)){
return SUCCESS;
}
return INPUT;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}
}


applicationContext.xml

xmlns="http://www.springframework.org/schema/beans"
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-2.0.xsd">








struts.xml

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">




/result.jsp
/index.jsp




web.xml

xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

index.jsp


contextConfigLocation
classpath:applicationContext.xml


struts
org.apache.struts2.dispatcher.FilterDispatcher


struts
/*


org.springframework.web.context.ContextLoaderListener



index.jsp

<%@ page language="java" pageEncoding="GB2312"%>
<%@ taglib uri="/struts-tags" prefix="s"%>


My JSP 'index.jsp' starting page



用户登陆










result.jsp

<%@ page language="java" pageEncoding="GB2312"%>
<%@ taglib uri="/struts-tags" prefix="s"%>


My JSP 'index.jsp' starting page



用户信息


用户名:
密码:${requestScope.password }

[@more@]http://www.blogjava.net/qin/archive/2008/09/24/230929.html?opt=admin

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/93029/viewspace-1018121/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-02-23

  • 博文量
    142
  • 访问量
    632458