首先建立一个web项目

引入需要的jar包

建立包com.bjpowernode.struts
创建LoginAction

package com.bjpowernode.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping; public class LoginAction extends Action{ @Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//struts1会自动的把相应的属性装载到对于的ActionForm中
LoginActionForm laf = (LoginActionForm)form;
if("admin".equals(laf.getUsername()) && "admin".equals(laf.getPassword())){
return mapping.findForward("success");
}
return mapping.findForward("error");
} }

创建LoginActionForm

package com.bjpowernode.struts;

import org.apache.struts.action.ActionForm;

public class LoginActionForm extends ActionForm {

    private String username;

    private String password;

    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;
} }

配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>struts1</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>struts1</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>

配置struts-config.xml,放置在WEB-INF下

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config>
<form-beans>
<form-bean name="LoginActionForm" type="com.bjpowernode.struts.LoginActionForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/login"
type="com.bjpowernode.struts.LoginAction"
name="LoginActionForm"
scope="request"> <forward name="success" path="/login_success.jsp"></forward>
<forward name="error" path="/login_error.jsp"></forward>
</action>
</action-mappings>
</struts-config>

提供index.jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<form action="login.do">
<input type="text" name="username"><br>
<input type="password" name="password"><br>
<input type="submit" value="登录">
</form>
</body>
</html>

提供login_success.jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'login_success.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
This is my JSP page. Success!!! <br>
</body>
</html>

提供login_error.jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'login_success.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
This is my JSP page. Error!!! <br>
</body>
</html>

struts1二:基本环境搭建的更多相关文章

  1. Appium+python自动化(二)- 环境搭建—下(超详解)

    简介 宏哥的人品还算说得过去,虽然很久没有搭建环境了,但是换了新电脑设备,一气呵成,将android的测试开发环境已经搭建准备完毕.上一篇android测试开发环境已经准备好, 那么接下来就是appi ...

  2. Selenium基础教程(二)环境搭建

    一.环境搭建 (1)初学者最佳环境: Python 2.7 + Selenium 2+ Firefox 46 (2)喜欢尝新的环境: Python 3.6 + Selenium 3+ Firefox ...

  3. cesium编程入门(二)环境搭建

    环境搭建 环境搭建 编译 node 安装 Node.js安装包及源码下载地址为:https://nodejs.org/en/download/. 安装完成后,打开命令行,输入:node -v,如果结果 ...

  4. 【Hbase二】环境搭建

    此笔记仅用于作者记录复习使用,如有错误地方欢迎留言指正,作者感激不尽,如有转载请指明出处 Hbase环境搭建 Hbase环境搭建 hadoop为HA的Hbase配置 Zookeeper集群的正常部署并 ...

  5. mybatis学习(二)——环境搭建

    开发环境搭建主要包括以下几步 1.新建一个JAVA项目(可以只建一个文件夹)  2.导入jar包 log4j是一个日志包,可以不加,这里为了定位问题添加了该包,下面两个包必须需要. 3.创建数据库 C ...

  6. RocketMQ系列(二)环境搭建

    RocketMQ的基本概念在上一篇中给大家介绍了,这一节将给大家介绍环境搭建.RocketMQ中最基础的就是NameServer,我们先来看看它是怎么搭建的. NameServer RocketMQ要 ...

  7. 大数据学习系列之二 ----- HBase环境搭建(单机)

    引言 在上一篇中搭建了Hadoop的单机环境,这一篇则搭建HBase的单机环境 环境准备 1,服务器选择 阿里云服务器:入门型(按量付费) 操作系统:linux CentOS 6.8 Cpu:1核 内 ...

  8. 分布式实时日志系统(二) 环境搭建之 flume 集群搭建/flume ng资料

    最近公司业务数据量越来越大,以前的基于消息队列的日志系统越来越难以满足目前的业务量,表现为消息积压,日志延迟,日志存储日期过短,所以,我们开始着手要重新设计这块,业界已经有了比较成熟的流程,即基于流式 ...

  9. 持续集成(二)环境搭建篇—内网邮件server搭建

    在我们的持续构建中,项目构建中出现错误提醒.或者开发者之间的沟通交流,进度汇报的事务,都是离不开一个通信工具.那就是邮件.在我们的项目开发中假设使用第三方的邮件平台,这肯定不是最好的选择.由于第三方的 ...

随机推荐

  1. 一些关于 checkbox的前台 jquery 操作 记录

    $(function() { //页面载入函数 var partList = jQuery.parseJSON( '${KeyWordsList}'); $.each(partList,functio ...

  2. supervisor-1:基础篇

    别人博客转载,做个记录 原文链接:http://lixcto.blog.51cto.com/4834175/1539136 有阵子没写博客了,这段时间一直在研究python django框架和前端相关 ...

  3. 在iIBatis中使用MySql中出现的配置问题

    1.首先需要下载mySQL-connector-net的安装包.可以通过下面两种方式,第一种是需要安装的,第二种是直接可以下载使用的. 第一种: http://dev.mysql.com/downlo ...

  4. PB12.5.2安装

    一.从12.5升级到12.5.2_build5550安装步骤: 1.安装VS2010及SP1 2.安装12.50(可以只装PB)DV68538-65-1250-01.zip 3.安装EBF20963 ...

  5. 用PS如何把图片调出时尚杂志色

    摘自:http://www.3lian.com/edu/2013/07-22/83061.html 01:打开图片,执行调整图层-色彩平衡;调整图层的标记-红色方框内图标. 02:色彩平衡-设置-点选 ...

  6. android开发中使不同的listview同时联动

    在做一个Android程序时,需要在一个屏幕上显示两个不同的listview,开始用< linearlayout>包裹这两个listview在<ScrollView >设置时, ...

  7. jQuery中设置form表单中action的值的方法

    下面介绍在jQuery中设置form表单中action的值的方法. $("#myFormId").attr("action", "userinfo.s ...

  8. Check a dll is x64 or x86

    Just read two good articles on this topic: http://stackoverflow.com/questions/480696/how-to-find-if- ...

  9. mas_makeConstraints && mas_remakeConstraints && mas_updateConstraints 用法与注意事项

    mas_makeConstraints && mas_remakeConstraints && mas_updateConstraints 用法与注意事项 字数400 ...

  10. bootstrap之伪元素

    bootstrap之伪元素 参考地址:http://www.cnblogs.com/keyi/p/5943178.html http://www.runoob.com/css/css-pseudo-e ...