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
版权为个人所有,欢迎大家转载;但转载时必须注明文章来源,且在文章开头明显处给明链接。
struts2 Eclipse 中集成strust2开发框架实例的更多相关文章
- Eclipse中集成Tomcat
问题: 很多时候在Eclipse中启动Tmocat后,不能访问本机的localhost:8080主页,并且其他项目也不能访问. 原因: 打开Tomcat下的webapp后也找补到项目目录,这是因为Ec ...
- Maven进价:eclipse中集成maven
一.M2Eclipse插件 m2eclipse是一个在Eclipse中集成Maven的插件,有了该插件,用户可以方便的在Eclipse中执行Maven命令.创建Maven项目.修改POM文件等. 下载 ...
- eclipse中集成python开发环境
转载:https://www.cnblogs.com/mywood/p/7272487.html Eclipse简介 Eclipse是java开发最常用的IDE,功能强大,可以在MAC和Windos上 ...
- Windows系统下在Eclipse中集成Python
我现在偶尔开发代码,已经不用Eclipse了,主要原因是查看Jar包中的代码反编译十分不便,项目加载的时候卡,偶尔还会崩溃 用Intellij IDEA和PyCharm 原来的笔记如何在Eclipse ...
- JAVA学习3:Eclipse中集成Tomcat
问题: 很多时候在Eclipse中启动Tmocat后,不能访问本机的localhost:8080主页,并且其他项目也不能访问. 原因: 打开Tomcat下的webapp后也找补到项目目录,这是因为Ec ...
- 在Eclipse 中集成SVN
在项目开发的过程中,我们需要用到版本控制工具,最常见的也就是SVN了,下面就来介绍最简单的一种在Elipse中集成svn工具. 第一步:下载 svn包,如site-1.6.5.zip或者site-1. ...
- 在Eclipse中集成Ant配置
提要:本文将向你展示如何使用Eclipse设置为Ant所用的属性值和环境变量,并简要分析如何配置Ant编辑器以便从Eclipse内部操作Ant文件. 一. 修改Ant Classpath 在使用一个可 ...
- Eclipse中集成Ant配置 (转)
目前的Eclipse都集成了ant,本文图示如何在eclipse下使用ant. 1.新建Java Project-新建Java文件HelloWorld.java HelloWorld.java pac ...
- 在tomcat目录下启动tomcat,可以正常访问tomcat主页,然在在eclipse中集成了tomcat却访问不了tomcat主页,却能访问发布的项目
tomcat server在eclipse中正常配置了,在eclipse建tomcat服务是在server 视图那里new server建立的,但把项目部署到tomcat后却发现tomcat主页报40 ...
随机推荐
- JS-JavaScript String 对象-string对象方法2: indexOf()、lastIndexOf()、charAt()
1.indexOf():可返回某个指定的字符串值在字符串中首次出现的位置. 1).语法:string.indexOf(searchvalue,start): searchvalue:必需.规定 ...
- BZOJ——3412: [Usaco2009 Dec]Music Notes乐谱
http://www.lydsy.com/JudgeOnline/problem.php?id=3412 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: ...
- Css 基础学习
css 基本选择器 css基本选择器有三种方法 第一种: class选择器 .c1{ color: red;} <div class='c1'>hello world</div> ...
- Delphi 释放数组中的数据
FillChar(aryTest[Low(aryTest)], Length(aryTest) * SizeOf(aryTest[Low(aryTest)]), 0);
- How To Commit Just One Data Block Changes In Oracle Forms
You have an Oracle Form in which you have multiple data blocks and requirement is to commit just one ...
- 【spring boot】application.properties官方完整文档【参考使用】
官方地址: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ 进入搜索: Appendice ...
- wxWidgets界面开发工具wxFormBuilder的使用
wxFormBuilder 下载地址:http://download.csdn.net/detail/lsmallstop/7013401 安装完成后,打开wxFormBuilder,可以在左侧工程子 ...
- 13.【nuxt起步】-部署到正式环境
已经购买centos服务器,并安装了nodejs环境 Secure CRT链接 Cd / Cd /var/www Mkdir test.abc.cn 用ftp 除了node_modules,其他都上传 ...
- ASP.NET MVC Web API 学习笔记---第一个Web API程序【转】
http://www.cnblogs.com/qingyuan/archive/2012/10/12/2720824.html 1. Web API简单说明 近来很多大型的平台都公开了Web API. ...
- js 保留两位小数 javascript
alert((0.9996*100).toFixed(2)); 得到99.96,这是我想要的! 使用Number.toFixed()可以格式数字显示任意的小数位!