Struts2官网:
http://struts.apache.org/
Struts2官网示例:
http://code.google.com/p/struts2-examples/downloads/list
一 运行环境: XP3+Myeclipse6.6+Tomcat7+JDK6
二 使用版本:
struts-2.2.1.1,所必需jar,参见附件
三 具体代码:
1 JSP页面代码:
A index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
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>Struts2 HelloWorld</title>
</head>
<body>
<a href="<s:url action="hello"/>">Hello</a>
</body>
</html>
B HelloWord.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
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>Struts2 Hello</title>
</head>
<body>
<s:property value="name"/><br>
<a href="${pageContext.request.contextPath}">返回</a>
<s:debug></s:debug>
</body>
</html>
2 HelloWordAction.java
package net.liuzd.struts2;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private String name = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String execute() throws Exception {
name = "咫尺天涯";
return SUCCESS;
}
}
3 配置文件
Struts2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="hello" extends="struts-default" namespace="/">
<action name="hello" class="net.liuzd.struts2.HelloWorldAction">
<result>/hello.jsp</result>
</action>
</package>
</struts>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<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.jsp
</welcome-file>
</welcome-file-list>
</web-app>
- 大小: 9.7 KB
分享到:
相关推荐
每个程序的开始:helloword
myeclipse6.0 jdk1.6 tomcat6.0
对于初学者来说是相当容易看懂的struts2
NULL 博文链接:https://wanglihu.iteye.com/blog/1405585
前几天在网上下载一个struts2的helloword的例子,那个作者也真够缺德的,搞个错误的程序,害得我查了一天的程序错误。 最后发现竟然是struts.xml被写成啦sturts.xml。 碰见这样的问题先鄙视下提供例子的作者, 再...
struts2的概述struts2下的HelloWord struts2基础 struts2做好准备 struts2的标志 struts2的Action讲解 struts2中的国际化 struts2转化器 struts2实现表单数据校验 struts2的基石-拦截器 struts2中实现IOC struts2中...
在网上找了好个struts2的例子结果都不好使报There is no Action mapped for namespace / and action name这个错,没办法自己搞了个好用的,myeclipse 6.0 +tomcat5.5 + jdk 1.5 引入项目后直接发布就可以了!
NULL 博文链接:https://quicker.iteye.com/blog/1217896
适合初学struts2者使用,不正确之处请指正
网上给的几个例子做总报些错,主要是需要的jar包没有完整的给出,我做的hello world是在struts2.1.8.1下实现的,导入项目即可正常运行。
NULL 博文链接:https://pwpw1218.iteye.com/blog/2106955
Struts2做的一个HelloWorld示例,使用Maven构建,导入请前先安装maven。
struts应用例子,这个例子帮助入门,获得开发struts应用的基本经验。该应用功能非常简单:接受用户输入姓名,然后输出姓名。
struts2 入门示例 HellWorld 工程源码。
一步一步详细描述用maven构建struts2的HelloWorld程序
我自己做的,利用struts 框加做了一个最简单的小例子,希望给入门的人有点用。里面struts都配置好了,按照标准,就是书上那种例子。我在网上找了好多都用了S:这样的标签,很麻烦,这个例子中直接用的普通input控件。
一个简单的struts2 helloword程序,配置信息,jar包都有