两个问题同时问一下:
我使用的myeclipse7.5,tomcat6,jdk1.6.0_18,struts-2.2.3;
1、404的问题:
初学struts,按照书上的指导,首先建立了名为test的web应用在tomcat的webapps下,其中test\WebRoot\WEB-INF\lib下拷入了基本jar包,并在java build path 中导入了,
在test\WebRoot\WEB-INF中的web.xml里配置如下 <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>在test\src中的struts.xml里的配置如下<!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.i18n.encoding" value="gb2312"/>
<include file="struts-default.xml"/>
<package name="action" extends="struts-default">
<action name="showWords" class="action.ShowWords">
<result name="success">showWords.jsp</result>
<result name="input">inputWords.jsp</result>
</action>
</package>
</struts>之后在test\src下建立了action包,里面编写了ShowWords.java(同时在WEB-INF\class\action中生成相应的.class文件),代码如下package action;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")
public class ShowWords extends ActionSupport{
private String name;
private String words;
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
public String getWords() {
return words;
} public void setWords(String words) {
this.words = words;
} public String execute()
{
if("".equals(name))
{
return INPUT;
}
else
{
words = "欢迎您:" + name;
return SUCCESS;
}
}
}然后在test\WebRoot下编写了inputWords.jsp页面,关键代码如下:
<form name="myForm" action="showWords.action" method="post">
请输入您的姓名:<input name="name" type="text"/><br/>
<input type="submit" name="mySubmit" value="提交"/>
</form>
最后在test\WebRoot下编写了showWords.jsp页面,关键代码如下:
<body>
${words}
</body>我是完全按书上的例子来的 ,但是点击inputwords.jap上的按钮后出现如下错误;
HTTP Status 404 - /test/showWords.action--------------------------------------------------------------------------------type Status reportmessage /test/showWords.actiondescription The requested resource (/test/showWords.action) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.262、如何使用struts标签:
网上有人说404的问题可能是struts2要使用自己的标签库,我试着直接在jsp中加入了如下代码:<s:form method="post" action="%{#request.contextPath}/orders">
<table>
<s:textfield name="clientName" label="Client"/>
<s:textfield name="amount" label="Amount" />
<tr>
<td colspan="2">
<s:submit />
</td>
</table>
</s:form>
在myeclipse的设计中是可以看到这些标签的,也不报错,但生成页面里缺什么都没有,我也按照网上的办法添加了<@taglibprefix="s"uri="/struts-tags">或是在web.xml中添加如下代码:
<taglib>
<taglib-uri>/struts-tags</taglib-uri>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
</taglib>
页面报无法找到struts-tags的错,如果多次刷新错误可能会消失,但依然无法看到文本框和按钮;
请问以上两个问题的原因在哪?tomcat还需要什么配置吗?在网上有很多类似问题的解答,我基本上都试了,还有些解答说使用tomcat5.5问题可能被解决,但我没有试,初学中,请帮忙看看我可能出现的错在哪里或是漏了哪一步!!
我使用的myeclipse7.5,tomcat6,jdk1.6.0_18,struts-2.2.3;
1、404的问题:
初学struts,按照书上的指导,首先建立了名为test的web应用在tomcat的webapps下,其中test\WebRoot\WEB-INF\lib下拷入了基本jar包,并在java build path 中导入了,
在test\WebRoot\WEB-INF中的web.xml里配置如下 <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>在test\src中的struts.xml里的配置如下<!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.i18n.encoding" value="gb2312"/>
<include file="struts-default.xml"/>
<package name="action" extends="struts-default">
<action name="showWords" class="action.ShowWords">
<result name="success">showWords.jsp</result>
<result name="input">inputWords.jsp</result>
</action>
</package>
</struts>之后在test\src下建立了action包,里面编写了ShowWords.java(同时在WEB-INF\class\action中生成相应的.class文件),代码如下package action;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")
public class ShowWords extends ActionSupport{
private String name;
private String words;
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
public String getWords() {
return words;
} public void setWords(String words) {
this.words = words;
} public String execute()
{
if("".equals(name))
{
return INPUT;
}
else
{
words = "欢迎您:" + name;
return SUCCESS;
}
}
}然后在test\WebRoot下编写了inputWords.jsp页面,关键代码如下:
<form name="myForm" action="showWords.action" method="post">
请输入您的姓名:<input name="name" type="text"/><br/>
<input type="submit" name="mySubmit" value="提交"/>
</form>
最后在test\WebRoot下编写了showWords.jsp页面,关键代码如下:
<body>
${words}
</body>我是完全按书上的例子来的 ,但是点击inputwords.jap上的按钮后出现如下错误;
HTTP Status 404 - /test/showWords.action--------------------------------------------------------------------------------type Status reportmessage /test/showWords.actiondescription The requested resource (/test/showWords.action) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.262、如何使用struts标签:
网上有人说404的问题可能是struts2要使用自己的标签库,我试着直接在jsp中加入了如下代码:<s:form method="post" action="%{#request.contextPath}/orders">
<table>
<s:textfield name="clientName" label="Client"/>
<s:textfield name="amount" label="Amount" />
<tr>
<td colspan="2">
<s:submit />
</td>
</table>
</s:form>
在myeclipse的设计中是可以看到这些标签的,也不报错,但生成页面里缺什么都没有,我也按照网上的办法添加了<@taglibprefix="s"uri="/struts-tags">或是在web.xml中添加如下代码:
<taglib>
<taglib-uri>/struts-tags</taglib-uri>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
</taglib>
页面报无法找到struts-tags的错,如果多次刷新错误可能会消失,但依然无法看到文本框和按钮;
请问以上两个问题的原因在哪?tomcat还需要什么配置吗?在网上有很多类似问题的解答,我基本上都试了,还有些解答说使用tomcat5.5问题可能被解决,但我没有试,初学中,请帮忙看看我可能出现的错在哪里或是漏了哪一步!!
2012-2-17 0:20:53 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.20.
2012-2-17 0:20:53 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2012-2-17 0:20:53 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8181
2012-2-17 0:20:53 org.apache.coyote.ajp.AjpAprProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-8009
2012-2-17 0:20:53 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 496 ms
2012-2-17 0:20:53 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2012-2-17 0:20:53 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.26
2012-2-17 0:20:53 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor host-manager.xml
2012-2-17 0:20:53 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor manager.xml
2012-2-17 0:20:54 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts2-blank.war
2012-2-17 0:20:54 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-default.xml]
2012-2-17 0:20:54 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2012-2-17 0:20:54 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-plugin.xml]
2012-2-17 0:20:54 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts.xml]
2012-2-17 0:20:54 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts2-rest-showcase.war
2012-2-17 0:20:55 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2012-2-17 0:20:55 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2012-2-17 0:20:55 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2012-2-17 0:20:55 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory again
2012-2-17 0:20:55 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory apps
2012-2-17 0:20:55 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory docs
2012-2-17 0:20:55 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory examples
2012-2-17 0:20:56 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2012-2-17 0:20:56 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2012-2-17 0:20:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
2012-2-17 0:20:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory test
2012-2-17 0:20:56 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8181
2012-2-17 0:20:56 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2012-2-17 0:20:56 org.apache.catalina.startup.Catalina start
信息: Server startup in 2599 ms
<!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.i18n.encoding" value="gb2312"/>
<include file="struts-default.xml"/>
<package name="action" namespace="/" extends="struts-default">
<action name="showWords" class="action.ShowWords">
<result name="success">showWords.jsp</result>
<result name="input">inputWords.jsp</result>
</action>
</package>
</struts>加上namespace
<package name="action" extends="struts-default">
<action name="showWords" class="action.ShowWords">
<result name="success">showWords.jsp</result>
<result name="input">inputWords.jsp</result>
</action>
</package>
,你的namespace应该为:“/test”
<package name="action" extends="struts-default" namespace="/">
<action name="showWords" class="action.ShowWords">
<result name="success">showWords.jsp</result>
<result name="input">inputWords.jsp</result>
</action>
</package>前台表单
<form name="myForm" action="/showWords.action" method="post">
请输入您的姓名:<input name="name" type="text"/><br/>
<input type="submit" name="mySubmit" value="提交"/>
</form>你web.xml应该没什么问题
如果还有问题继续说明。
<@taglibprefix="s"uri="/struts-tags"> 这个需要放到jsp里最上面【调用之前、】
而且你写错了吧?【<@taglib prefix="s" uri="/struts-tags"> 】 空格要明确啊、这个他会根据你写的路径去找、你看看你web-inf里面是否有这个tld文件
<taglib>
<taglib-uri>/struts-tags</taglib-uri>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
</taglib> 你把这段去掉 直接就在jsp上面填写那句uri 然后在
<s:debug></s:debug>在页面上写上、
看能出来不、
【楼主精神很执着啊、继续保持】
1、我按照你的配置编写了struts.xml中的<package name="action" namespace="/" extends="struts-default">,在前台form中也写成了<form action="/showWords.action" method = "post">,现在执行后报的错为The requested resource (/showWords.action) is not available.路径问题?配置问题?类始终没有挂上。
2、<%@ taglib prefix = "s" uri="/struts-tags"%>我现在是这样写的,就放在了jsp的最上面 ,还是找不到,我写成了uri="struts-tags",第一次没通过,但刷了几次,页面居然通过了,没报错,再生成时又报了“File "/WebRoot/struts-tags" not found”这样的错,然后我发现我的web-inf根本就没有这个文件,我又从struts2-core-2.2.3.jar中找到了struts-tags.tld文件,于是放入了test\webroot\web-inf下,结果还是不行,我感觉是路径的问题;
3、还有个问题,myeclipse不能像eclipse那样启动tomcat吗?我发现只有停了tomcat的服务才可以用myeclipse的服务来启动tomcat。
{
if("".equals(name))
{
return INPUT;
}
else
{
words = "欢迎您:" + name;
return SUCCESS;
}
}
这个方法
1.在前台的提交页面中,<Form>中的 action路径是不需要斜线的..
并且,你的 action必须在配置文件中设置好.关于这点,大致看了下楼朱最初的代码,都是有做,但一定不要出现问题...这类问题若出现,将非常麻烦.
2.<%@ taglib prefix = "s" uri="/struts-tags"%>这样的写法根本没有问题,楼主不应改动...
若这样写Myeclipse有报错,那就一定是导入的包有问题.楼主可以直接找人要一份齐全的包,然后全部重新导.
3.至于楼主说的像Eclipse那样启动Tomcat,个人不是很清楚具体启动方式.但Myeclipse是有自带Tomcat的,这点与Eclipse非常大的差别.楼主说的停了Tomcat才能用Myeclipse的服务器启动,大概是因为你启动外部Tomcat导致端口被占用,所以内部的Tomcat才无法启动
{
return SUCCESS;
}
这样写看行不?
请输入您的姓名:<input name="name" type="text"/><br/>
<input type="submit" name="mySubmit" value="提交"/>
</form>
最后在test\WebRoot下编写了showWords.jsp页面,关键代码如下:
<body>
${words}
</body>name="myForm" struts2没有form
改成
<form action="showWords.action" method="post">
另外开你的应用名是否正确 windows-prerences里面 是不是test
<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>
第一你过滤器不知道对不?
我用过org.apache.struts2.dispatcher.FilterDispatcher
第二
<url-pattern>/*</url-pattern>
改成
<url-pattern>/*.action</url-pattern>
这个不用改,没错
<Host>
<Context docBase="E:\..\webRoot" path="/应用名" reloadable="true"/>
</Host>
直接启动tomcat就行
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>">这段代码没有?
1.
严重: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter2.
严重: Dispatcher initialization failed
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
缺少包: javassist-3.11.0.GA.jar
3.
严重: Could not create JarEntryRevision for [jar:file:/D:/application/apache-tomcat-6.0.30/webapps/SSH1/WEB-INF/lib/struts2-core-2.3.4.jar]!
java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
缺少包: commons-io-2.0.1.jar
4.
严重: Exception starting filter struts2
java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
缺少包: commons-lang3-3.1.jar