zoukankan      html  css  js  c++  java
  • No result defined for action action.LoginAction and result success 问题解决

    转自:https://blog.csdn.net/dongzhout/article/details/43699699

    搭建好SSH2框架,写一个简单的登陆功能,提交表单的时候遇到这个问题:


    配置文件如下:

    web.xml:

    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <web-app version="3.0"   
    3.     xmlns="http://java.sun.com/xml/ns/javaee"   
    4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
    6.     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">  
    7.   <display-name></display-name>   
    8.   <context-param>  
    9. <param-name>contextConfigLocation</param-name>  
    10. <param-value>classpath:applicationContext.xml</param-value>  
    11. </context-param>  
    12. <listener>  
    13. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    14. </listener>  
    15.   <welcome-file-list>  
    16.     <welcome-file>index.jsp</welcome-file>  
    17.   </welcome-file-list>  
    18.   <filter>  
    19.     <filter-name>struts2</filter-name>  
    20.     <filter-class>  
    21.         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
    22.     </filter-class>  
    23.     <init-param>  
    24. <param-name>config</param-name>  
    25. <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>  
    26. </init-param>  
    27.   </filter>  
    28.   <filter-mapping>  
    29.     <filter-name>struts2</filter-name>  
    30.     <url-pattern>*.action</url-pattern>  
    31.   </filter-mapping>  
    32.     <filter-mapping>  
    33.     <filter-name>struts2</filter-name>  
    34.     <url-pattern>*.jsp</url-pattern>  
    35.   </filter-mapping></web-app>  

    spring配置文件:applicationContext.xml:
    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <web-app version="3.0"   
    3.     xmlns="http://java.sun.com/xml/ns/javaee"   
    4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
    6.     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">  
    7.   <display-name></display-name>   
    8.   <context-param>  
    9. <param-name>contextConfigLocation</param-name>  
    10. <param-value>classpath:applicationContext.xml</param-value>  
    11. </context-param>  
    12. <listener>  
    13. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    14. </listener>  
    15.   <welcome-file-list>  
    16.     <welcome-file>index.jsp</welcome-file>  
    17.   </welcome-file-list>  
    18.   <filter>  
    19.     <filter-name>struts2</filter-name>  
    20.     <filter-class>  
    21.         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
    22.     </filter-class>  
    23.     <init-param>  
    24. <param-name>config</param-name>  
    25. <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>  
    26. </init-param>  
    27.   </filter>  
    28.   <filter-mapping>  
    29.     <filter-name>struts2</filter-name>  
    30.     <url-pattern>*.action</url-pattern>  
    31.   </filter-mapping>  
    32.     <filter-mapping>  
    33.     <filter-name>struts2</filter-name>  
    34.     <url-pattern>*.jsp</url-pattern>  
    35.   </filter-mapping></web-app>  

    struts2.1配置文件struts.xml:
    1. <?xml version="1.0" encoding="UTF-8" ?>  
    2. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">  
    3. <struts>  
    4.     <constant name="struts.objectFactory" value="spring" />  
    5.     <package name="default" extends="struts-default" >  
    6.         <action name="userLogin" class="LoginAction">  
    7.             <result name="success">/success.jsp</result>  
    8.             <result name="input">/login.jsp</result>  
    9.         </action>  
    10.     </package>  
    11.   
    12. </struts>      

    LoginAction.java:
    1. public String execute() {  
    2.     // TODO Auto-generated method stub  
    3.       
    4.     return SUCCESS;  
    5. }  

    登陆页面 login.jsp:
    1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
    2. <%@taglib prefix="s" uri="/struts-tags"%>  
    3. <%  
    4.     String path = request.getContextPath();  
    5.     String basePath = request.getScheme() + "://"  
    6.             + request.getServerName() + ":" + request.getServerPort()  
    7.             + path + "/";  
    8. %>  
    9.   
    10. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
    11. <html>  
    12. <head>  
    13. <base href="<%=basePath%>">  
    14.   
    15. <title>My JSP 'login.jsp' starting page</title>  
    16.   
    17. <meta http-equiv="pragma" content="no-cache">  
    18. <meta http-equiv="cache-control" content="no-cache">  
    19. <meta http-equiv="expires" content="0">  
    20. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
    21. <meta http-equiv="description" content="This is my page">  
    22. <!-- 
    23.     <link rel="stylesheet" type="text/css" href="styles.css"> 
    24.     -->  
    25.   
    26. </head>  
    27.   
    28. <body>  
    29.     This is my JSP page.  
    30.     <br>  
    31.     <s:form action="userLogin.action">  
    32.         <s:textfield name="username" label="用户名" />  
    33.         <s:password name="password" label="密码"></s:password>  
    34.         <s:submit type="button" value="登陆" />  
    35.     </s:form>  
    36. </body>  
    37. </html>  

    成功跳转页面 success.jsp:
    1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
    2. <%@taglib prefix="s" uri="/struts-tags"%>  
    3. <%  
    4.     String path = request.getContextPath();  
    5.     String basePath = request.getScheme() + "://"  
    6.             + request.getServerName() + ":" + request.getServerPort()  
    7.             + path + "/";  
    8. %>  
    9.   
    10. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
    11. <html>  
    12. <head>  
    13. <base href="<%=basePath%>">  
    14.   
    15. <title>My JSP 'success.jsp' starting page</title>  
    16.   
    17. <meta http-equiv="pragma" content="no-cache">  
    18. <meta http-equiv="cache-control" content="no-cache">  
    19. <meta http-equiv="expires" content="0">  
    20. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
    21. <meta http-equiv="description" content="This is my page">  
    22. <!-- 
    23.     <link rel="stylesheet" type="text/css" href="styles.css"> 
    24.     -->  
    25.   
    26. </head>  
    27.   
    28. <body>  
    29.     This is my JSP page.  
    30.     <br> Welcome!  
    31.     <h5>  
    32.         <s:property value="username" />  
    33.     </h5>  
    34.     <br>  
    35.     <h6>  
    36.         <s:property value="password" />  
    37.     </h6>  
    38. </body>  
    39. </html>  

    这个是修改之后的正确代码,原来错误代码的struts.xml中的action的name是login,login.jsp中的action="login.action",将这两个action改成“userLogin”之后就没有问题了,改成Login也是可以的。不知道是什么问题,希望了解的大神们指点一下。


  • 相关阅读:
    致研究者的一封信
    机器学习简介
    The resource about the Machine Learning(Cont.)
    哈佛箴言
    Google图片搜索新算法 图片版PageRank
    top conferences and journals in Machine Learning
    做科研的几点体会
    数百本外文数学EBOOK免费下载
    Machine Learning Algorithm Tutorials
    在批处理中实现等待/延迟/暂停
  • 原文地址:https://www.cnblogs.com/sharpest/p/5809853.html
Copyright © 2011-2022 走看看