struts2.3 创建工程
1:在该网站下载struts2.3.16.3,目前为最新版。http://www.struts.apache.org/download.cgi
不妨下载“Full Distribution”版本
下载完后解压。
2.
用eclipse创建一个Dynamic Web project项目
这里要注意一点,创建的src文件的.class文件要放到WEB-INF/classes下。那么怎么放拟?按照如下图操作。
file-》new -》Dynamic Web project -》输入项目名称(hellostruts),点击next。这里要注意了,看图。
将图中下面的build classes 改为WebContent/WEB-INF/classes WebContent\WEB-INF\classes
点击完成

3.
然后把一些第一步解压出来的必要的组件添加到该项目的WebContent/WEB-INF/lib下。
面对这108个组件我们该如何选择?有时候选择多了不一定是好的;这里我只选择了必要的9个jar文件
整个工程结构如图,路劲要一致:

4.接下来是编写jsp页面了
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:a action="hello">hello</s:a>
</body>
</html>
success.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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:property value="hello"/>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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">
<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>
<!-- index page -->
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
接着是在src目录下建立一个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>
<package name="default" namespace="/" extends="struts-default">
<action name="hello" class="com.action.TestAction">
<result>/success.jsp</result>
</action>
</package>
</struts>
struts.properties
<struts.il8n.encoding value="UTF-8"/>
接着,在src目录下建立一个包,然后在这个包下new一个类;
TestAction.java
package com.action;
import com.opensymphony.xwork2.ActionSupport; public class TestAction extends ActionSupport {
private static final long serialVersionUID=1L;
private String hello;
public String getHello(){
return hello;
}
public void setHello(String hello){
this.hello=hello;
}
public String execute() throws Exception{
hello="hello world";
return SUCCESS;
}
}
5.运行, 右键工程名--> run as --> run on server
struts2.3 创建工程的更多相关文章
- Maven2 根据项目生成模版项目,并使用该模板批量创建工程。
Maven 3 创建自己的模版,并使用模版创建工程 1.建立样板Maven工程: myModel 2.进入 myModel 工程根目录执行:mvn archetype:create-from-proj ...
- [liusy.api-SMJ]-创建工程范例 MAVEN archetype 学习阶段(一)
由于这个架构需要好多不同能力的工程,为了创建方便减少冗余,创建工程范例尤为重要 学习阶段: 参考资料 http://maven.apache.org/archetype/maven-archetype ...
- Java Struts2 POI创建Excel文件并实现文件下载
Java Struts2 POI创建Excel文件并实现文件下载2013-09-04 18:53 6059人阅读 评论(1) 收藏 举报 分类: Java EE(49) Struts(6) 版权声明: ...
- scrapy爬虫成长日记之创建工程-抽取数据-保存为json格式的数据
在安装完scrapy以后,相信大家都会跃跃欲试想定制一个自己的爬虫吧?我也不例外,下面详细记录一下定制一个scrapy工程都需要哪些步骤.如果你还没有安装好scrapy,又或者为scrapy的安装感到 ...
- Sublime Text : 创建工程
Sublime Text 可以很方便地管理多个工程.使用Sublime Text的Projects,可以将不同根目录的文件组织起来成为一个工程,而不用将所有的文件都放到一个根目录下面. 1. 创建工程 ...
- AltiumDesigner学习笔记(一)——创建工程与原理图文件
一.创建工程与原理图文件 1.通过菜单创建PCB工程 (1)File - New - Project - PCB Project,即可在当前工作区创建新的PCB工程 (2)新建工程并不直接在硬盘中创建 ...
- Xamarin iOS编写第一个应用程序创建工程
Xamarin iOS编写第一个应用程序创建工程 在Xcode以及Xamarin安装好后,就可以在Xamarin Studio中编写程序了.本节将主要讲解在Xamarin Studio中如何进行工程的 ...
- ODI 12c中使用Groovy脚本创建工程
本文主要介绍在ODI中使用groovy创建工程,并添加一个表转换的映射.要创建groovy脚本,可以从ODI Studio的菜单:工具->Groovy->新脚本 打开一个编辑窗口.在执行下 ...
- Qt_Window@Qt Command Prompt从命令行创建工程
#include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplicatio ...
随机推荐
- Android 经验: 5555 端口会被 adb 误认为 emulator
在本机启动 Android, 再用本机的的 adb 去连接 adb connect 127.0.0.1:5555 而后 adb devices 查看 user@ubuntu:~$ adb device ...
- Linux下安装zookeeper集群
首先,准备三台Linux虚拟机 三台机器 centos01 :192.168.1.168(lxs001) centos03 :192.168.1.178(lxs003) centos03 :1 ...
- 【CSS学习笔记】a标签的四种伪类
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- bzoj3504: [Cqoi2014]危桥 网络流
一种网络流建图的思路吧,改天最好整理一波网络流建图思路 #include <bits/stdc++.h> using namespace std; int n,h,t,a1,a2,an,b ...
- 队列Queue FIFO先进先出 栈Stack FILO先进后出
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- sublime & atom 插件
1. autofilename(sublime) autocomplete-paths (atom): 自动路径 2. autoprefixer: 自动添加前缀 : https://github.c ...
- ASP.NET MVC Url中带点号出现404错误的解决方案
由于项目需求,项目的路由设计如下 config.Routes.MapHttpRoute( name: "Get/Put Sku", routeTemplate: "api ...
- 仅以一个前端开发人员的角度看微信小程序
看了几天的小程序(当然也包括了上手书写),才有了这篇博文,非技术贴,只是发表下个人观点,仅以个人技术能力来看小程序. 首先说下优点: 调试工具:官方的工具还是做了很多工作,包括监听文件变动自动刷新,编 ...
- COCOS2D-JS入门-官网template源码解析
首先介绍几个概念: 导演: 导演 (Director)是Cocos2d-JS引擎抽象的一个对象,Director是整个Cocos2d-JS引擎的核心,是整个游戏的导航仪,游戏中的一些常用操作就是由Di ...
- Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference
E/AndroidRuntime﹕ FATAL EXCEPTION: mainProcess: org.example.magnusluca.drawertestapp, PID: 3624java. ...