Tomcat与Struts1.2.9的简单例子和一个常见问题
2010-10-29 23:31
525 查看
Tomcat与Struts1.2.9的简单例子和一个常见问题(原创)
首先说明,我要解释的问题是Cannot find message resources under key org.apache.struts.action.MESSAGE错误,如果对你没有帮助,就请不要继续看下去了。
先讲解一下这个例子,首先下载Struts软件包,我下的是Struts1.2.9,你可以去官方网站(http://struts.apache.org/index.html)下载。
好,下面开始配置这个简单的例子:
我是在Tomcat中配置的,首先建立个虚拟映射目录(如果不会就参阅其他文章),比如"D:/webapps/mystruts/"映射成"/mystruts",这样你就可以通过访问"http://localhost:8080/mystruts"访问"D:/webapps/mystruts/"这个目录。
在你创建的目录中,建立WEB-INF文件夹,在WEB-INF中建立classes、lib和tld文件夹。解压缩Struts软件包,将lib文件夹下的commons-*.jar(*代表任意位任意字符)和struts.jar文件全拷贝到你所建立的WEB-INF/lib文件夹中,将压缩包lib文件夹下的*.tld(*代表任意位任意字符)全部拷贝到WEB-INF/tld文件夹中。
在WEB-INF目录下建立两个文件web.xml、struts-config.xml分别写入如下代码:
web.xml中写入:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<display-name>Struts Blank Application</display-name>
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-html</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
</web-app>
struts-config.xml中写入:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
</form-beans>
<global-forwards>
</global-forwards>
<action-mappings>
</action-mappings>
<message-resources parameter="ApplicationResources"/>
</struts-config>
然后在WEB-INF中建立ApplicationResources.properties文件,其中输入:
index.title=MyStruts
在mystruts(以你自己建立的名字为准)目录建立test.jsp文件,有如下内容:
<%@ page contentType="text/html;charset=gb2312" %>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<html:html locale="true">
<head>
<html:base/>
<title>
<bean:message key="index.title"/>
</title>
</head>
<body>
你好 Struts!
</body>
</html:html>
随后用http://localhost:8080/mystruts/test.jsp(以你自己建立的名字为准)来访问该文件,如果页面显示"你好 Struts!"字样,并且页面标题是MyStruts就是成功了。
下面谈问题。如果出现Cannot find message resources under key org.apache.struts.action.MESSAGE,是说明找不到ApplicationResources.properties,你要注意两方面设置。
第一:在web.xml适当位置要有如下设置:
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
第二:在struts-config.xml中适当位置要有如下设置:
<message-resources parameter="ApplicationResources"/>
推荐句话多插入如下位置:</action-mappings>"放到这里"</struts-config>
第三:确保ApplicationResources.properties文件在你建立的WEB-INF/classes文件夹中,而且其中有关于index.title的设置(当然,以你要提取的key名称为准)。
另外,我还要说明,你也可以把ApplicationResources.properties放到classes文件夹下其它目录,但struts-config.xml中的设置要改。例如:
<message-resources parameter="test/ApplicationResources"/>
你就要把ApplicationResources.properties放入WEB-INF/classes/test文件夹下。
neonlight <neonlight@live.cn>,BLOG:http://blog.csdn.net/neonlight 转载请注明出处,谢谢!2006年08月12日
首先说明,我要解释的问题是Cannot find message resources under key org.apache.struts.action.MESSAGE错误,如果对你没有帮助,就请不要继续看下去了。
先讲解一下这个例子,首先下载Struts软件包,我下的是Struts1.2.9,你可以去官方网站(http://struts.apache.org/index.html)下载。
好,下面开始配置这个简单的例子:
我是在Tomcat中配置的,首先建立个虚拟映射目录(如果不会就参阅其他文章),比如"D:/webapps/mystruts/"映射成"/mystruts",这样你就可以通过访问"http://localhost:8080/mystruts"访问"D:/webapps/mystruts/"这个目录。
在你创建的目录中,建立WEB-INF文件夹,在WEB-INF中建立classes、lib和tld文件夹。解压缩Struts软件包,将lib文件夹下的commons-*.jar(*代表任意位任意字符)和struts.jar文件全拷贝到你所建立的WEB-INF/lib文件夹中,将压缩包lib文件夹下的*.tld(*代表任意位任意字符)全部拷贝到WEB-INF/tld文件夹中。
在WEB-INF目录下建立两个文件web.xml、struts-config.xml分别写入如下代码:
web.xml中写入:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<display-name>Struts Blank Application</display-name>
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-html</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
</web-app>
struts-config.xml中写入:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
</form-beans>
<global-forwards>
</global-forwards>
<action-mappings>
</action-mappings>
<message-resources parameter="ApplicationResources"/>
</struts-config>
然后在WEB-INF中建立ApplicationResources.properties文件,其中输入:
index.title=MyStruts
在mystruts(以你自己建立的名字为准)目录建立test.jsp文件,有如下内容:
<%@ page contentType="text/html;charset=gb2312" %>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<html:html locale="true">
<head>
<html:base/>
<title>
<bean:message key="index.title"/>
</title>
</head>
<body>
你好 Struts!
</body>
</html:html>
随后用http://localhost:8080/mystruts/test.jsp(以你自己建立的名字为准)来访问该文件,如果页面显示"你好 Struts!"字样,并且页面标题是MyStruts就是成功了。
下面谈问题。如果出现Cannot find message resources under key org.apache.struts.action.MESSAGE,是说明找不到ApplicationResources.properties,你要注意两方面设置。
第一:在web.xml适当位置要有如下设置:
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
第二:在struts-config.xml中适当位置要有如下设置:
<message-resources parameter="ApplicationResources"/>
推荐句话多插入如下位置:</action-mappings>"放到这里"</struts-config>
第三:确保ApplicationResources.properties文件在你建立的WEB-INF/classes文件夹中,而且其中有关于index.title的设置(当然,以你要提取的key名称为准)。
另外,我还要说明,你也可以把ApplicationResources.properties放到classes文件夹下其它目录,但struts-config.xml中的设置要改。例如:
<message-resources parameter="test/ApplicationResources"/>
你就要把ApplicationResources.properties放入WEB-INF/classes/test文件夹下。
neonlight <neonlight@live.cn>,BLOG:http://blog.csdn.net/neonlight 转载请注明出处,谢谢!2006年08月12日
相关文章推荐
- 一个简单的MyEclipse5.5 + Struts + Hibernate + Tomcat 5.5列子
- [Struts]学习日记1 - 一个简单的例子
- JVisualvm监控不到本地Tomcat问题总结和简单使用例子
- 一个简单的Struts例子
- 一个典型的例子解决常见的高级Windows程序设计问题
- python 常见面试问题(1)-python 输出中文问题/求list的交集或差集/一个简单的socket编程/python 异常处理
- 一个简单的Struts例子
- Jbpm4.4+hibernate3.5.4+spring3.0.4+struts2.1.8整合例子(附完整的请假流程例子,jbpm基础,常见问题解决)
- (3.1.4.1)一个简单的struts例子
- 一个简单的html测试tomcat本地服务器的问题处理一
- Jbpm4.4+hibernate3.5.4+spring3.0.4+struts2.1.8整合例子(附完整的请假流程例子,jbpm基础,常见问题解决)
- 一个简单的servlet导致eclipse无法启动tomcat的问题
- 一个简单的struts的例子
- c#中子线程控制进度条的一个简单例子(多线程问题)
- 一个简单的Struts Hibernate入门例子(上)
- 一个简单的html测试tomcat本地服务器的问题处理二
- 一个简单的优化例子(锁问题)
- 介绍Struts 1.1 框架基本原理,以及介绍Struts 1.1 安装和一个简单的例子。
- 一个简单的Struts Hibernate入门例子(下)
- 一个简单的优化例子(锁问题)