<?xml version="1.0" encoding="GBK"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<!-- 定义一个业务逻辑组件,实现类为MyServiceImp,
此处的id必须与Action的setter方法名对应 -->
<bean id="ms"
class="org.crazyit.app.service.impl.MyServiceImpl"/>
</beans>
<?xml version="1.0" encoding="GBK"?>
<project name="spring" basedir="." default="">
<property name="src" value="src"/>
<property name="dest" value="classes"/> <path id="classpath">
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${dest}"/>
</path> <target name="compile" description="Compile all source code">
<delete dir="${dest}"/>
<mkdir dir="${dest}"/>
<copy todir="${dest}">
<fileset dir="${src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
<javac destdir="${dest}" debug="true" includeantruntime="yes"
deprecation="false" optimize="false" failonerror="true">
<src path="${src}"/>
<classpath refid="classpath"/>
<compilerarg value="-Xlint:deprecation"/>
</javac>
</target> </project>
<?xml version="1.0" encoding="GBK"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<!-- 使用ContextLoaderListener初始化Spring容器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 定义Struts 2的FilterDispathcer的Filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- FilterDispatcher用来初始化Struts 2并且处理所有的WEB请求。 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<?xml version="1.0" encoding="GBK"?>
<!-- 指定Struts 2配置文件的DTD信息 -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- 配置了系列常量 -->
<constant name="struts.i18n.encoding" value="GBK"/>
<constant name="struts.devMode" value="true"/>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<package name="lee" extends="struts-default">
<!-- 定义处理用户请求的Action -->
<action name="login"
class="org.crazyit.app.action.LoginAction">
<!-- 为两个逻辑视图配置视图页面 -->
<result name="error">/WEB-INF/content/error.jsp</result>
<result>/WEB-INF/content/welcome.jsp</result>
</action>
<!-- 让用户直接访问该应用时列出所有视图页面 -->
<action name="*">
<result>/WEB-INF/content/{1}.jsp</result>
</action>
</package>
</struts>
package org.crazyit.app.action;

import com.opensymphony.xwork2.ActionSupport;

import org.crazyit.app.service.*;
/**
* Description:
* <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
* <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class LoginAction extends ActionSupport
{
// 下面是用于封装用户请求参数的两个成员变量
private String username;
private String password;
// 系统所用的业务逻辑组件
private MyService ms;
// 设值注入业务逻辑组件所必需的setter方法
public void setMs(MyService ms)
{
this.ms = ms;
}
// username的setter和getter方法
public void setUsername(String username)
{
this.username = username;
}
public String getUsername()
{
return this.username;
}
// password的setter和getter方法
public void setPassword(String password)
{
this.password = password;
}
public String getPassword()
{
return this.password;
} // 处理用户请求的execute方法
public String execute() throws Exception
{
// 调用业务逻辑组件的validLogin()方法
// 验证用户输入的用户名和密码是否正确
if (ms.validLogin(getUsername(), getPassword()) > 0)
{
addActionMessage("哈哈,整合成功!");
return SUCCESS;
}
else
{
return ERROR;
}
}
}
package org.crazyit.app.service;

/**
* Description:
* <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
* <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public interface MyService
{
int validLogin(String username , String pass);
}
package org.crazyit.app.service.impl;

import org.crazyit.app.service.*;
/**
* Description:
* <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
* <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class MyServiceImpl implements MyService
{
public int validLogin(String username , String pass)
{
// 此处只是简单示范,故直接判断用户名、密码是否符合要求
if ( username.equals("crazyit.org")
&& pass.equals("leegang") )
{
return 99;
}
return -1;
}
}
<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>登录页面</title>
</head>
<body>
<h3>用户登录</h3>
<s:form action="login">
<s:textfield name="username" label="用户名"/>
<s:textfield name="password" label="密码"/>
<tr align="center">
<td colspan="2">
<s:submit value="登录" theme="simple"/>
<s:reset value="重设" theme="simple"/>
</td>
</tr>
</s:form>
</body>
</html>
<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>成功页面</title>
</head>
<body>
您已经登录!<br/>
<s:actionmessage />
</body>
</html>

  

<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author yeeku.H.lee kongyeeku@163.com
version 1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date:
--%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>错误页面</title>
</head>
<body>
您不能登录!
</body>
</html>

最新文章

  1. Eclipse背景颜色设置(设置成豆沙绿色保护眼睛,码农保护色)
  2. Linux下查找文件:which、whereis、locate、find 命令的区别
  3. JS魔法堂:再识Bitwise Operation &amp; Bitwise Shift
  4. FLAG是什么公司
  5. BZOJ 1511: [POI2006]OKR-Periods of Words
  6. Connect模块解析
  7. ueditor样式过滤问题
  8. (转)word2vec前世今生
  9. 全栈一路坑之使用django创建博客
  10. 一个公网地址部署LVS/DR模式
  11. BZOJ 1592: [Usaco2008 Feb]Making the Grade 路面修整
  12. Android事件分发详解(三)——ViewGroup的dispatchTouchEvent()源码学习
  13. css技巧之如何实现ul li边框重合
  14. Jquery库自带的动画效果方法记录
  15. MVC3在页面上获取当前控制器名称、Action名称以及路由参数
  16. 【PL/SQL Developer】动态执行表不可访问,本会话的自动统计被禁止
  17. Win7怎么显示文件的后缀名
  18. jmeter ---json几种读取方式,ArrayList循环读取
  19. Java面试题—初级(1)
  20. appium 出现报错“A new session could not be created. (Original error: Requested a new session but one was in progress)”的解决方式!

热门文章

  1. 现在啊还不太清楚 nodejs和coffeescript 的关系
  2. 从maven安装配置到idea成功创建maven项目
  3. 光流法draw_flow()函数报错
  4. android开发实战-记账本APP(二)
  5. Git详解之初次运行
  6. Docker底层架构之简介
  7. Sqlite命令行基本操作
  8. Day of Week
  9. 如何为wordpress 的文章添加分页
  10. JAVA环境配置(Windows10)