struts2 Eclipse 中集成strust2开发框架实例
下面通过建立一个小的实例具体来说明Eclipse 集成struts2,以下实例采用的为 struts2 版本为 struts2 2.2.3.1 为应用.
1. 下载struts2的开发包
第一步: 在浏览器中输入 http://apache.org
第二步:在apche的页面项目中选择struct 点击连接进入相关页面
第三步: 点击download选择下载 struct2 ,本例子中选择 :struts2 2.2.3.1,下载完后解压,lib中的为strut2在开发中用到的包.
2. 建立WEB项目
第一步:打开Eclipse点击[文件]->Dynamic Web Project,输入相关信息如下图:
第二步:引用java开发包tomcat包及struts2必备包.
(1) 应用 tomcat服务器包文件
A. 右键Struts2->点击properties 然后选择左侧的 java build path ->libraries
(2) 添加jre包文件
A. 右键Struts2->点击properties 然后选择左侧的 java build path ->libraries
添加完后点击ok即可.
第三步:strust2开发lib包直接拷贝到WEB-INF/lib下面即可
实例的建立:
1. 首先介绍实例包含的文件: struts.xml, HelloWorldAction java类,web.xml ,HelloWorld.jsp,index.jsp
2. 内容如下:
(1) struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" /><package name="helloworld" extends="struts-default"><action name="hello" class="com.northeasttycoon.struts2.HelloWorldAction" method="execute"><result name="success">/HelloWorld.jsp</result></action></package>
</struts>
(2) web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- northeasttycoon -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>Struts 2</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
</web-app>
(3) HelloWorldAction.java
/*** @author NorthEastTycoon**/
package com.northeasttycoon.struts2;
public class HelloWorldAction{private String name;private String passWord;public String getPassWord() {return passWord;
}
public void setPassWord(String passWord) {this.passWord = passWord;
}
public String execute() throws Exception {return "success";}public String getName() {return name;}public void setName(String name) {this.name = name;}
}
(4) HelloWorld.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>欢迎,
<s:property value="name"/>登陆</br>
密码为,
<s:property value="passWord"/></br>
</body>
</html>
(5) index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello World</title>
</head>
<body><h1>Hello World From Struts2</h1><form action="hello"><label for="name">Please enter your name</label><input type="text" name="name"/><br/><label for="passWord">Please enter your passWord</label><input type="text" name="passWord"/><br/><input type="submit" value="Say Hello"/></form>
</body>
</html>
以上为例子全部内容经过调试.
效果如下图:
备注:
作者:东北大亨
博客:http://www.cnblogs.com/northeastTycoon/p/5617958.html
版权为个人所有,欢迎大家转载;但转载时必须注明文章来源,且在文章开头明显处给明链接。
转载于:https://www.cnblogs.com/northeastTycoon/p/5617958.html
struts2 Eclipse 中集成strust2开发框架实例相关推荐
- Eclipse中集成Tomcat
问题: 很多时候在Eclipse中启动Tmocat后,不能访问本机的localhost:8080主页,并且其他项目也不能访问. 原因: 打开Tomcat下的webapp后也找补到项目目录,这是因为Ec ...
- 在Eclipse中集成Genymotion模拟器插件
在Eclipse中集成Genymotion模拟器插件 作为Android码农,很多人都喜欢Genymotion模拟器,因为好使.因为速度快.但 ...
- Maven 系列 3:如何在 Eclipse 中集成配置 Maven(以 apache-maven-3.6.2、eclipse-jee-2019-09-R-win32-x86_64 为例)
文章目录 前言 一.打开 Eclipse 进入 Maven 配置页面 二.将本地 Maven 路径对应到 Eclipse 中 三.将配置文件集成到 Eclipse 中 四.开启 Eclipse 的 M ...
- eclipse中集成jad反编译
[size=large]转载地址:[url]http://www.blogjava.net/sy1214520/archive/2009/04/29/209371.html[/url] 很早就听说过e ...
- 在Eclipse中集成Ant编程之配置篇
提要:本文将向你展示如何使用Eclipse设置为Ant所用的属性值和环境变量,并简要分析如何配置Ant编辑器以便从Eclipse内部操作Ant文件. 一. 修改Ant Classpath 在使用一个可 ...
- java eclipse profile_在 Eclipse 中集成JProfiler 进行 JAVA 项目性能分析
1.双击安装 2.选择路径 默认路径:Install into:C:\Program Files\jprofiler11 自定义:Customize installation 选择完成后点击 next ...
- eclipse中集成tomcat8
首先jdk要确定已经配置好. 一.按照自己系统选择tomcat8下载:(http://tomcat.apache.org/download-80.cgi) 下载完解压. 二.eclipse中 File ...
- ssm项目集成ftp_SSM开发框架实例(struts+spring+springmvc)
概述 可以直接下载导入Myeclipse直接使用. 项目基于Myeclipse/jdk1.8 项目基于Maven做依赖管理 项目基于Mysql5.6做数据库管理 功能 1.Spring boot 1. ...
- Eclipse中集成SVN
这里介紹Eclipse的SVN Plugin,叫做Subclipse,官方网站的下载地址在http://subclipse.tigris.org/,也提供了update site http://sub ...
最新文章
- 【 FPGA 】特定情况下消除不稳定态的方法
- Tech Ed上Windows 7值得关注的课程
- [Bugku CTF——Pwn] pwn4
- 拦截器,过滤器,监听器原理
- 我的世界基岩版种子和java版种子_我的世界:对萌新最友好的种子,基岩版通用,对老玩家也很适合!...
- MySql存储过程异常处理示例
- XSS跨站脚本小结(转)
- 通达OA 太牛了!工作流表单设计中级联菜单原来可以这样实现(图文)
- 【正点原子探索者STM32F407开发板例程连载+教学】第44章 FATFS文件系统实验
- win Server 2012 R2 密钥
- c#删除sheet_C#中实现插入、删除Excel分页符的方法
- qt程序在win10正常运行win7电脑上崩溃
- 利用四位共阳数码管显示小数
- 视频转图像序列工具FreeVideoToJPGConverter(5.0.101.201版)下载安装及使用(Windows)
- 北大博士唐大仕推荐C#学习网站
- jsp页面在tomcat部署后访问为源代码页面
- C++之string类型详解
- CC2540开发入门
- Wannafly挑战赛26:B冥土追魂(模拟?贪心?暴力?)
- OpenCV入门(十七)快速学会OpenCV 16 视频处理