Chinaunix首页 | 论坛 | 博客
  • 博客访问: 823001
  • 博文数量: 137
  • 博客积分: 3477
  • 博客等级: 中校
  • 技术积分: 1409
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-30 21:53
文章分类

全部博文(137)

文章存档

2024年(8)

2023年(10)

2022年(4)

2021年(10)

2020年(9)

2018年(1)

2017年(1)

2014年(4)

2013年(3)

2012年(12)

2011年(24)

2010年(2)

2009年(8)

2008年(6)

2007年(34)

2006年(1)

分类: 系统运维

2012-09-15 19:45:18

风之舞原创,转载请注明来源。
=============================================================

开发工具升级到 MyEclipse 10.1 , 系统自带了 struts2 插件,原来一直用 struts 1.21 开发。听说 struts2 相比 struts 1 有了很大的提高,这次想试试 struts2 开发,谁知确遇到了很郁闷的问题。

先看我的代码:

web.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="3.0" xmlns="" xmlns:xsi="" xsi:schemaLocation=" /web-app_3_0.xsd">
  3.     <context-param>
  4.         <param-name>contextConfigLocation</param-name>
  5.         <param-value>/WEB-INF/applicationContext.xml</param-value>
  6.     </context-param>
  7.     <filter>
  8.         <filter-name>struts2</filter-name>
  9.         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  10.     </filter>
  11.     <filter-mapping>
  12.         <filter-name>struts2</filter-name>
  13.         <url-pattern>/*</url-pattern>
  14.     </filter-mapping>
  15.     <listener>
  16.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  17.     </listener>
  18.     <servlet>
  19.         <servlet-name>dispatcher</servlet-name>
  20.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  21.         <load-on-startup>2</load-on-startup>
  22.     </servlet>
  23.     <servlet-mapping>
  24.         <servlet-name>dispatcher</servlet-name>
  25.         <url-pattern>*.htm</url-pattern>
  26.     </servlet-mapping>
  27.     <session-config>
  28.         <session-timeout>
  29.             30
  30.         </session-timeout>
  31.     </session-config>
  32.     <welcome-file-list>
  33.         <welcome-file>login.jsp</welcome-file>
  34.     </welcome-file-list>
  35. </web-app>

struts.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8" ?>

  2. <!DOCTYPE struts PUBLIC
  3.         "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  4.         "">

  5. <struts>
  6.             <package name="org.casystem.action" extends="struts-default">
  7.                 <action name="login.action" class="org.casystem.action.LoginAction">
  8.                         <result name="success">/success.jsp</result>
  9.                         <result name="error">/error.jsp</result>
  10.                 </action>
  11.         </package>
  12. </struts>

login.jsp

点击(此处)折叠或打开

  1. <%--
  2. Views should be stored under the WEB-INF folder so that
  3. they are not accessible except through controller process.

  4. This JSP is here to provide a redirect to the dispatcher
  5. servlet but should be the only JSP outside of WEB-INF.
  6. --%>
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8. <%@taglib prefix="s" uri="/struts-tags" %>
  9. <html>
  10.     <head>
  11.         <title>This is CaSystem Login JSP</title>
  12.     </head>
  13.     <body>
  14.         <form action="login.action" method="post">
  15.             <table>
  16.                 <tr>
  17.                     <td>用户:</td>
  18.                     <td><input type="text" name="user.username"></td>
  19.                 </tr>
  20.                 <tr>
  21.                     <td>密码:</td>
  22.                     <td><input type="password" name="user.password"></td>
  23.                 </tr>
  24.                 <tr>
  25.                     <td><input type="reset" value="重置" /></td>
  26.                     <td><input type="submit" value="提交" /></td>
  27.                 </tr>
  28.             </table>
  29.         </form>
  30.     </body>
  31.     
  32. </html>

LoginAction.java

点击(此处)折叠或打开

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package org.casystem.action;


  6. import com.opensymphony.xwork2.ActionSupport;
  7. import org.casystem.model.User;

  8. public class LoginAction extends ActionSupport {
  9.         
  10.         /**
  11.          *
  12.          */
  13.         private static final long serialVersionUID = 1L;
  14.         private User user;

  15.         @Override
  16.         public String execute() throws Exception {
  17.                 // TODO Auto-generated method stub
  18.                 if ("test".equals(user.getUsername()) && "123456".equals(user.getPassword())){
  19.                         return SUCCESS;
  20.                 }else{
  21.                         return ERROR;
  22.                 }
  23.         }
  24.         
  25.         public User getUser(){
  26.                 return user;
  27.         }
  28.         
  29.         public void setUser(User user){
  30.                 this.user = user;
  31.         }

  32. }

User.java

点击(此处)折叠或打开

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package org.casystem.model;

  6. import java.io.Serializable;
  7. /**
  8.  *
  9.  * @author work
  10.  */
  11. public class User implements Serializable {
  12.     private String username;
  13.     private String password;
  14.     
  15.     public String getUsername(){
  16.         return username;
  17.     }
  18.     
  19.     public void setUsername(String username){
  20.         this.username = username;
  21.     }
  22.     
  23.     public String getPassword(){
  24.         return password;
  25.     }
  26.     
  27.     public void setPassword(String password){
  28.         this.password = password;
  29.     }
  30.     
  31. }

error.jsp

点击(此处)折叠或打开

  1. <%--
  2.     Document : error
  3.     Created on : 2012-9-12, 11:05:11
  4.     Author : work
  5. --%>

  6. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  7. <%@taglib prefix="s" uri="/struts-tags"%>
  8. <!DOCTYPE html>
  9. <html>
  10.     <head>
  11.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  12.         <title>ERROR JSP</title>
  13.     </head>
  14.     <body>
  15.         <h1>您输入的用户ID或密码有误,请重新<a href="login.jsp">登录</a>.</h1>
  16.     </body>
  17. </html>

success.jsp

点击(此处)折叠或打开

  1. <%--
  2.     Document : success
  3.     Created on : 2012-9-12, 11:02:32
  4.     Author : work
  5. --%>

  6. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  7. <%@taglib prefix="s" uri="/struts-tags"%>
  8. <!DOCTYPE html>
  9. <html>
  10.     <head>
  11.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  12.         <title>JSP Page</title>
  13.     </head>
  14.     <body>
  15.         <h1>Hello , <s:property value="user.username"></s:property> WelCom to CaSystem Site.</h1>
  16.     </body>
  17. </html>

满怀信心的运行,结果 。。。

点击(此处)折叠或打开

  1. Using CATALINA_BASE: /home/work/.netbeans/7.2/apache-tomcat-7.0.27.0_base
  2. Using CATALINA_HOME: /home/work/apache-tomcat-7.0.27
  3. Using CATALINA_TMPDIR: /home/work/.netbeans/7.2/apache-tomcat-7.0.27.0_base/temp
  4. Using JRE_HOME: /usr/java/jdk1.6.0_34
  5. Using CLASSPATH: /home/work/apache-tomcat-7.0.27/bin/bootstrap.jar:/home/work/apache-tomcat-7.0.27/bin/tomcat-juli.jar
  6. 2012-9-12 14:25:51 org.apache.catalina.core.AprLifecycleListener init
  7. 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/jdk1.6.0_34/jre/lib/i386/server:/usr/java/jdk1.6.0_34/jre/lib/i386:/usr/java/jdk1.6.0_34/jre/../lib/i386:/usr/java/jdk1.6.0_34/jre/lib/i386/client:/usr/java/jdk1.6.0_34/jre/lib/i386:/usr/java/jdk1.6.0_34/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
  8. 2012-9-12 14:25:51 org.apache.coyote.AbstractProtocol init
  9. 信息: Initializing ProtocolHandler ["http-bio-8084"]
  10. 2012-9-12 14:25:51 org.apache.coyote.AbstractProtocol init
  11. 信息: Initializing ProtocolHandler ["ajp-bio-8009"]
  12. 2012-9-12 14:25:51 org.apache.catalina.startup.Catalina load
  13. 信息: Initialization processed in 705 ms
  14. 2012-9-12 14:25:51 org.apache.catalina.core.StandardService startInternal
  15. 信息: Starting service Catalina
  16. 2012-9-12 14:25:51 org.apache.catalina.core.StandardEngine startInternal
  17. 信息: Starting Servlet Engine: Apache Tomcat/7.0.27
  18. 2012-9-12 14:25:51 org.apache.catalina.startup.HostConfig deployDescriptor
  19. 信息: Deploying configuration descriptor /home/work/.netbeans/7.2/apache-tomcat-7.0.27.0_base/conf/Catalina/localhost/ROOT.xml
  20. 2012-9-12 14:25:53 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
  21. 信息: Parsing configuration file [struts-default.xml]
  22. 2012-9-12 14:25:53 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
  23. 信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
  24. 2012-9-12 14:25:53 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
  25. 信息: Parsing configuration file [struts-plugin.xml]
  26. 2012-9-12 14:25:53 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
  27. 信息: Parsing configuration file [struts.xml]
  28. 2012-9-12 14:25:53 org.apache.catalina.startup.HostConfig deployDescriptor
  29. 信息: Deploying configuration descriptor /home/work/.netbeans/7.2/apache-tomcat-7.0.27.0_base/conf/Catalina/localhost/manager.xml
  30. 2012-9-12 14:25:53 org.apache.catalina.startup.HostConfig deployDescriptor
  31. 信息: Deploying configuration descriptor /home/work/.netbeans/7.2/apache-tomcat-7.0.27.0_base/conf/Catalina/localhost/CaSystem.xml
  32. 2012-9-12 14:25:56 org.springframework.web.context.ContextLoader initWebApplicationContext
  33. 信息: Root WebApplicationContext: initialization started
  34. 2012-9-12 14:25:56 org.springframework.context.support.AbstractApplicationContext prepareRefresh
  35. 信息: Refreshing Root WebApplicationContext: startup date [Wed Sep 12 14:25:56 CST 2012]; root of context hierarchy
  36. 2012-9-12 14:25:56 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  37. 信息: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
  38. 2012-9-12 14:25:56 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  39. 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@133f6dd: defining beans []; root of factory hierarchy
  40. 2012-9-12 14:25:56 org.springframework.web.context.ContextLoader initWebApplicationContext
  41. 信息: Root WebApplicationContext: initialization completed in 268 ms
  42. 2012-9-12 14:25:56 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  43. 信息: Parsing configuration file [struts-default.xml]
  44. 2012-9-12 14:25:56 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  45. 信息: Parsing configuration file [struts-plugin.xml]
  46. 2012-9-12 14:25:56 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  47. 信息: Parsing configuration file [struts.xml]
  48. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  49. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.ObjectFactory)
  50. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  51. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.FileManager)
  52. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  53. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)
  54. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  55. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)
  56. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  57. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)
  58. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  59. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)
  60. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  61. 信息: Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)
  62. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  63. 信息: Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)
  64. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  65. 信息: Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)
  66. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  67. 信息: Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)
  68. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  69. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)
  70. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  71. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)
  72. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  73. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)
  74. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  75. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)
  76. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  77. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)
  78. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  79. 信息: Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)
  80. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  81. 信息: Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)
  82. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
  83. 信息: Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)
  84. 2012-9-12 14:25:57 org.springframework.web.servlet.FrameworkServlet initServletBean
  85. 信息: FrameworkServlet 'dispatcher': initialization started
  86. 2012-9-12 14:25:57 org.springframework.context.support.AbstractApplicationContext prepareRefresh
  87. 信息: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Wed Sep 12 14:25:57 CST 2012]; parent: Root WebApplicationContext
  88. 2012-9-12 14:25:57 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  89. 信息: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
  90. 2012-9-12 14:25:57 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  91. 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@17c50b9: defining beans [org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0,urlMapping,viewResolver,indexController]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@133f6dd
  92. 2012-9-12 14:25:57 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
  93. 信息: Mapped URL path [/index.htm] onto handler 'indexController'
  94. 2012-9-12 14:25:57 org.springframework.web.servlet.FrameworkServlet initServletBean
  95. 信息: FrameworkServlet 'dispatcher': initialization completed in 294 ms
  96. 2012-9-12 14:25:57 org.apache.coyote.AbstractProtocol start
  97. 信息: Starting ProtocolHandler ["http-bio-8084"]
  98. 2012-9-12 14:25:57 org.apache.coyote.AbstractProtocol start
  99. 信息: Starting ProtocolHandler ["ajp-bio-8009"]
  100. 2012-9-12 14:25:57 org.apache.catalina.startup.Catalina start
  101. 信息: Server startup in 6094 ms
  102. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
  103. 警告: Could not find action or result
  104. There is no Action mapped for namespace / and action name netbeans-tomcat-status-test. - [unknown location]
  105. at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
  106. at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
  107. at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
  108. at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
  109. at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
  110. at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
  111. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  112. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  113. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
  114. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  115. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  116. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  117. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  118. at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  119. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  120. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  121. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  122. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  123. at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  124. at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  125. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  126. at java.lang.Thread.run(Thread.java:662)
  127. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
  128. 警告: Could not find action or result
  129. There is no Action mapped for namespace / and action name netbeans-tomcat-status-test. - [unknown location]
  130. at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
  131. at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
  132. at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
  133. at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
  134. at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
  135. at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
  136. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  137. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  138. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
  139. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  140. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  141. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  142. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  143. at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  144. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  145. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  146. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  147. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  148. at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  149. at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  150. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  151. at java.lang.Thread.run(Thread.java:662)
  152. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
  153. 警告: Could not find action or result
  154. There is no Action mapped for namespace / and action name netbeans-tomcat-status-test. - [unknown location]
  155. at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
  156. at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
  157. at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
  158. at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
  159. at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
  160. at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
  161. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  162. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  163. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
  164. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  165. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  166. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  167. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  168. at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  169. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  170. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  171. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  172. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  173. at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  174. at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  175. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  176. at java.lang.Thread.run(Thread.java:662)
  177. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
  178. 警告: Could not find action or result
  179. There is no Action mapped for namespace / and action name netbeans-tomcat-status-test. - [unknown location]
  180. at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
  181. at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
  182. at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
  183. at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
  184. at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
  185. at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
  186. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  187. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  188. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
  189. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  190. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  191. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  192. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  193. at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  194. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  195. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  196. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  197. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  198. at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  199. at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  200. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  201. at java.lang.Thread.run(Thread.java:662)
  202. 2012-9-12 14:25:57 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
  203. 警告: Could not find action or result
  204. There is no Action mapped for namespace / and action name netbeans-tomcat-status-test. - [unknown location]
  205. at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
  206. at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
  207. at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
  208. at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
  209. at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
  210. at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
  211. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  212. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  213. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
  214. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  215. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  216. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  217. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  218. at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  219. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  220. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  221. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  222. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  223. at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  224. at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  225. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  226. at java.lang.Thread.run(Thread.java:662)
  227. 2012-9-12 14:25:58 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
  228. 警告: Could not find action or result
  229. There is no Action mapped for namespace / and action name netbeans-tomcat-status-test. - [unknown location]
  230. at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
  231. at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
  232. at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
  233. at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
  234. at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
  235. at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
  236. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  237. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  238. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
  239. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  240. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  241. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  242. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  243. at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  244. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  245. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  246. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  247. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  248. at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  249. at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  250. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  251. at java.lang.Thread.run(Thread.java:662)

悲剧了,出错了。

仔细观察输出的日志文件信息,发现其中又这样的错误提示:
  1. Could not find action or result
  2. There is no Action mapped for namespace / and action name netbeans-tomcat-status-test. - [unknown location]

根据错误提示,仔细检查了login.jsp 和 LoginAction.java 以及 struts.xml 中的代码,没问题啊 ... ...

折腾了两天,终于发现是包冲突。原来在 MyEclipse 10.1 中(不仅仅是 MyEclipse 10.1 , 还有 NetBeans 7.2),当添加 struts2 支持(你的应用->MyEclipse-Add Struts Capabilities)的时候,会将 struts2 的所有支持包全部引入,然而遗憾的是,这个引入的所有的包其实是有冲突的。

我的解决办法。首先在新建一个 web 工程以后,就添加 struts2 的支持,添加完了以后,在你的 web 工程后直接将 Struts Core Library 从你的 build path 中删除,我们其实只是想要它的配置文件 struts.xml 和 在 web.xml 中的配置,如果你记性很好,自己添加也可以。

然后将 struts2 的基本支持包直接在工程中拷贝到你的应用的 lib 目录之下。我用的 struts 2.3.4 的包。

再按照正常的开发方式进行开发,编写我上面的那些代码和配置信息(主要是 struts.xml 中的信息).

编写完成后,发布你的应用,然后在你的 浏览器的地址栏输入 ,即可以看到 login.jsp 的输入界面。

我们分别输入正确的用户和密码,错误的用户和密码,页面正确的跳转到了我们希望的页面。

阅读(2337) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

snow8882012-09-15 20:45:59

我们再来看看 LoginAction.java 的代码。

package org.casystem.action;
这句话指明了我们的 LoginAction.java 位于 org.casystem.action 的包内。

import com.opensymphony.xwork2.ActionSupport;
引入 Struts2 的 ActionSupport 的支持。
import org.casystem.model.User;
引入 User 类的支持,这个类也是我们自己编写的,在后面我们会谈到这个类的信息。

public class LoginAction extends ActionSupport {
这句话告诉我们,LoginAction 继承于 ActionSupport。

if 条件语句中有两个返回,大致意思是如果 用户 = “test” 并且 密码 =“123456” 的时

snow8882012-09-15 20:24:33

下面就前面的内容进行一个简单的分析:
首先看 web.xml 文件,其中有如下内容:
<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
     &nb