1.获取struts的jar包

1.1首先在http://struts.apache.org/download.cgi#struts23163这里下载 struts的文件包(选择struts-2.3.16.3-all)

1.2解压得到例如以下的目录

apps目录下是struts的一些官方样例

docs已久是官方api说明文档

lib包是struts全部的jar包

src则是一些样例的资源文件

注意:接下来我们须要取得我们须要的jar包,而不是lib文件夹下所有的jar文件,假设所有导入有可能会发生冲突

那么哪些才是我们须要的jar包呢?

1.3打开apps目录,解压struts2-blank.war得到演示样例的文件

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzYxNjk3Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

1.4打开WEB-INF/lib 里面的jar包就是我们基本struts操作须要的jar包。把他们取出来待用。


2.在项目中取得struts的支持

2.1 打开eclipse 新建动态web

2.2将第一步取得jar包拷贝到项目WEB-INF/lib文件夹下

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzYxNjk3Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

2.3在项目中加入web.xml并配置

在WEB-INF根文件夹下加入web.xml文件并配置struts的过滤器

<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" 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"> <display-name>Struts Blank</display-name> <filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> </web-app>
</span>

3.建立struts并实现

3.1在scr中新建action继承ActionSupport

<span style="font-size:18px;">package fzl.struts.demo;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {

	@Override
public String execute() throws Exception {
System.out.println("--------UserAction-------");
return "success";
} } </span>

3.2在配置struts.xml文件

在src根文件夹下建立struts.xml文件并进行一下配置

<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<package name="default" namespace="/" extends="struts-default">
<action name="hello" class="fzl.struts.demo.UserAction">
<result>/hello.jsp</result> </action> </package>
</struts>
</span>

4建立显示层文件

在WEB-INF目录下建立hello.jsp

<span style="font-size:18px;"><%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body> <h2>hello struts</h2>
<h2>这是我的第一个struts程序</h2>
</body>
</html></span>

启动Tomcat、在地址栏输入http://localhost:port号/StrutsDemo/hello 就可以得到例如以下页面

到这里我们的struts的配置已经完毕并实现了。

最后总结一下

基本步骤:

1、拷贝struts的jar到项目中(apps中的blank项目中能够找到这些jar包)

2、将struts2的过滤器加入到web.xml中

3、配置struts2的配置文件(在src文件夹中创建struts.xml文件)

4、创建action(action就是一个POJO类)

4.1、为action编写execute方法

4.2、在struts.xml文件里配置action和返回结果集

struts开发&lt;在eclipse中配置struts. 一&gt;的更多相关文章

  1. Android开发:在Eclipse中配置Android环境

    一.文件需要: https://pan.baidu.com/s/1-XCSSPW5JGyPRlvwRVSfmA 提取码:m5t8 NDK过大没有上传在这个文件里. 二.在Eclipse中配置Tools ...

  2. 将struts的jar包拷贝到WEB-INF/lib导致eclipse中配置好的javadoc失效

    我通过这个步骤导入了struts的jar包并且配置好了javadoc,且亲测可用: http://www.cnblogs.com/qrlozte/p/3173805.html 但是当我把struts的 ...

  3. eclipse中配置c++开发环境 Eclipse + CDT + MinGW

    转自eclipse中配置c++开发环境 Eclipse + CDT + MinGW 基本框架:Eclipse + CDT + MinGW 背景知识: CDT:CDT 是完全用 Java 实现的开放源码 ...

  4. 如何在Eclipse中配置python开发环境

    考虑到网上关于Eclipse中配置Python开发环境的文章千篇一律,故写此文以总结. 本文主要内容是:三种Pydev配置方法和一种PyDev卸载方法. 本文的前提是你已经安装了Eclipse和pyt ...

  5. (原创)超详细一步一步在eclipse中配置Struts2环境,无基础也能看懂

    (原创)超详细一步一步在eclipse中配置Struts2环境,无基础也能看懂 1. 在官网https://struts.apache.org下载Struts2,建议下载2.3系列版本.从图中可以看出 ...

  6. eclipse中配置struts2出现There is no Action mapped for namespace [/] and action name [Login] associated wi

    下午在eclipse中配置struts2时报: There is no Action mapped for namespace [/] and action name [Login] associat ...

  7. 【Java Web】Eclipse中配置Marven环境

    1  Marven简介 Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具,由Apache软件基金会所提供.基于项目对象模型(缩写:POM)概念,Maven利用一个中央信 ...

  8. 如何在eclipse中配置反编译工具JadClipse

    Q:为什么有必要在开发环境中配置反编译工具呢? A:  当运行引用了第三方jar包项目时,突然报出了jar包中的某个类的某一行出现异常.我们想看一下这个class文件的代码时,经常出现了如下图所示的场 ...

  9. Maven插件的简介,安装及在eclipse中配置

    1.Maven简介 1.Maven介绍 Maven是一个基于项目对象模型(POM:project object model)的概念的纯java开发的开源的项目管理工具.Maven把我们的工程抽像一个对 ...

随机推荐

  1. Verilog学习笔记基本语法篇(八)········ 结构说明语句

    Verilog中的任何过程都可以属于以下四种结构的说明语句; 1) initial;  2) always;  3) task;   4) function; 1) initial说明语句: 一个程序 ...

  2. BFS:UVa220 ACM/ICPC 1992-Othello(黑白棋)

    Othello Othello is a game played by two people on an 8 x 8 board, using disks that are white on one ...

  3. PAT Basic 1027

    1027 打印沙漏 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号:各行 ...

  4. debian 中的jdk

    1 openjdk 2 debian安装java的脚本 3 下载bin自己编译

  5. saltstack管理八之常用执行模块

    所有执行模块: http://docs.saltstack.cn/zh_CN/latest/ref/states/all/index.html 常用模块:cmd, cron, file, mount, ...

  6. CentOS下配置LVM和RAID

    1.CentOS配置LVM http://www.cnblogs.com/mchina/p/linux-centos-logical-volume-manager-lvm.html http://ww ...

  7. IIS PUT

    测试版本:IIS6.0 利用工具 1.IIS PUT Scaner By ZwelL 2.桂林老兵IIS写权限利用程序   -------------------------------------- ...

  8. appium+python自动化-adb shell模拟点击事件(input tap)

    前言 appium有时候定位一个元素很难定位到,或者说明明定位到这个元素了,却无法点击,这个时候该怎么办呢? 求助大神是没用的,点击不了就是点击不了,appium不是万能的,这个时候应该转换思路,换其 ...

  9. document.execCommand

    document.execCommand 在firefox浏览器执行不好,但是在其他浏览器有时候使用会非常方便. 比如在input标签中使用: onkeyup="if(isNaN(value ...

  10. 03-offsetParent属性

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...