struts2.1.6 使用札记(一)
来源:互联网 发布:mac读写ntfs破解版 编辑:程序博客网 时间:2024/05/01 17:12
最近想学下struts2。手头刚好有本孙鑫的《struts2深入详解》,于是对着开始学习,不过由于现在的struts出的版本是2.1.6,孙老师还是2.0时代的例子,导致我第一个helloworld就虚掉了,于是多方搜索,结合官方的doc,终于跑动了第一个实例……
文件层次结构:
导包的时候注意不要把所有的包都导进去,不然就会出现
Unable to load configuration. - bean - jar:file:/d:/Tomcat6/webapps/EJBBookStoreWebModule/WEB-INF/lib/struts2-convention-plugin-2.1.6.jar!/struts-plugin.xml:30:119
此类的错误,这应该是struts2.1.6的一个bug吧~~~
HelloWorld.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h2><s:property value="message" /></h2>
</body>
</html>
*****************
***************************
HelloWorld.java
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport {
public static final String MESSAGE = "Struts is up and running ...";
public String execute() throws Exception {
setMessage(MESSAGE);
return SUCCESS;
}
private String message;
public void setMessage(String message){
this.message = message;
}
public String getMessage() {
return message;
}
}
*******************
*****************************
web.xml
<?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">
<welcome-file-list>
<welcome-file>HelloWorld.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.mycompany.myapp.actions</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
******************
*****************
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="tutorial" extends="struts-default">
<action name="HelloWorld" class="tutorial.HelloWorld">
<result>/HelloWorld.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
*******************************************
然后发布后运行 http://localhost:8080/struts2/HelloWorld.action 就可以看到屏幕上的
Struts is up and running ...
- struts2.1.6 使用札记(一)
- 深圳札记(一)
- 无题札记(一)
- ruby札记(一)
- 工作札记(一)
- WCF札记(一)
- 面试札记(一)
- OWC控件的使用学习札记(一)
- Linux 使用札记(一) 硬盘安装Fedora 15 DVD
- Linux 使用札记(一) 硬盘安装Ubuntu 11.04
- linux安装札记(一)
- JAVA学习札记(一)
- 英语发音札记(一)
- 计算语言学札记(一)
- c++学习札记(一)
- CLR 学习札记(一)
- 基础加固札记(一)
- 前端开发札记(一)
- Java中的switch语句
- 原码、反码和补码
- 线程同步:事件对象
- 很恍惚,我在这里安了个家
- FreeMarker基本语法知识
- struts2.1.6 使用札记(一)
- 语言的歧义
- Struts 2.1.6 搭建环境
- 给Ubuntu 9.04配置3D桌面
- Common Dbutils组件用法详解(含源代码)(转)
- vc++自定义息的使用
- 光端机,话路复用器,交换机
- 出国的人
- Applet编程——Applet与Servlet通信(转载)