转自: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. </struts>

LoginAction.java:

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

登陆页面 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. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  10. <html>
  11. <head>
  12. <base href="<%=basePath%>">
  13. <title>My JSP 'login.jsp' starting page</title>
  14. <meta http-equiv="pragma" content="no-cache">
  15. <meta http-equiv="cache-control" content="no-cache">
  16. <meta http-equiv="expires" content="0">
  17. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  18. <meta http-equiv="description" content="This is my page">
  19. <!--
  20. <link rel="stylesheet" type="text/css" href="styles.css">
  21. -->
  22. </head>
  23. <body>
  24. This is my JSP page.
  25. <br>
  26. <s:form action="userLogin.action">
  27. <s:textfield name="username" label="用户名" />
  28. <s:password name="password" label="密码"></s:password>
  29. <s:submit type="button" value="登陆" />
  30. </s:form>
  31. </body>
  32. </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. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  10. <html>
  11. <head>
  12. <base href="<%=basePath%>">
  13. <title>My JSP 'success.jsp' starting page</title>
  14. <meta http-equiv="pragma" content="no-cache">
  15. <meta http-equiv="cache-control" content="no-cache">
  16. <meta http-equiv="expires" content="0">
  17. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  18. <meta http-equiv="description" content="This is my page">
  19. <!--
  20. <link rel="stylesheet" type="text/css" href="styles.css">
  21. -->
  22. </head>
  23. <body>
  24. This is my JSP page.
  25. <br> Welcome!
  26. <h5>
  27. <s:property value="username" />
  28. </h5>
  29. <br>
  30. <h6>
  31. <s:property value="password" />
  32. </h6>
  33. </body>
  34. </html>

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

No result defined for action action.LoginAction and result success 问题解决的更多相关文章

  1. HTTP Status 404 - No result defined for action com.csdhsm.struts.action.LoginAction and result error

    智商拙计的问题,没有找到为类LoginAction和error找到定义,然后重新去struts.xml去看,我类个去,我居然把result写成了ERROR <result name=" ...

  2. Struts 2.x No result defined for action 异常

      这是我跑struts2的第一个例子,跑的也够郁闷的,这个问题烦了我几个钟... 2011-5-10 10:10:17 com.opensymphony.xwork2.util.logging.co ...

  3. No result defined for action com.lk.IndexAction and result success

    意图访问一个 /es/index.action 竟然出现: [SAE ] ERROR [05-11 13:54:32] [http-80-5] com.opensymphony.xwork2.util ...

  4. no result defined for action

    1.no result defined for action .......and result input    或者 no result defined for action .......and ...

  5. HTTP Status 404 - No result defined for action com.hebky.oa.classEntity.action.EntitysAction and result input

    在开发中总遇到这个问题,No result defined for action:原因:Action中的属性值为空的时候,Struts2的默认拦截器会报错,但是又找不到input的Result,不能够 ...

  6. Struts2问题,已解决No result defined for action and result input

    struts2.1.8 必须在struts.xml中配置namespace属性 如果你在2.0中一切OK,但是在2.1中确出现了No result defined for action的异常,就是在因 ...

  7. validators配置要点及No result defined for action报错解决方案

    在做JavaEE SSH项目时,接触到validators验证. 需要了解validators配置,或者遇到No result defined for action 这个错误时,可查阅本文得到有效解决 ...

  8. struts异常:No result defined for action

    问题描述: No result defined for action com.freedom.funitureCityPSIMS.controller.login.CheckAction and re ...

  9. SSH配置struts校验发生No result defined for action actions.AdminLoginAction and result input

    配置struts校验发生No result defined for action actions.AdminLoginAction and result input,但是登录,success.jsp, ...

  10. No result defined for action com.nynt.action.ManageAction and result input问题

    No result defined for action com.nynt.action.ManageAction and result input 问题原因: 1). 在action类中定义的一个r ...

随机推荐

  1. Eclipse安装SVN客户端

    在Eclipse中安装SVN客户端有个好处,不用兼容其它操作系统都能保持一致的操作.比如再Linux下SVN客户端软件体验相对较差,但是基于命令行的操作却在Linux下无所不能. 一.通过在线安装 地 ...

  2. Codeforces Beta Round #61 (Div. 2) D. Petya and His Friends 想法

    D. Petya and His Friends time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. MySQL随机取数据

    // 随机取9个 $rand_sql = "SELECT * FROM `tf_product` WHERE (`id` >= ((SELECT MAX(`id`) FROM `tf_ ...

  4. Node.js初接触(一)

    本来还在纠结着到底要学哪一种后台语言呢,突然发现node.js很火,既然能被这么多人推崇,自然是有他的优势的.去百度百科看了一眼,或许是我理解能力太差,并没有了解到很多关于node.js的东西,大概就 ...

  5. Adobe 产品更新直接下载链接

    mac:http://prodesigntools.com/adobe-cc-2015-updates-links-mac.html win:http://prodesigntools.com/ado ...

  6. cassandra cqlsh 和 python客户端

    Keyspaces A cluster is a container for keyspaces. A keyspace is the outermost container for data in ...

  7. IntelliJ IDEA配置tomcat【全程详解】

    相关博客:IntelliJ IDEA创建Maven+SSM+Tomcat+Git项目[全程详解] 创建好web项目后,需要将项目部署到Tomcat中运行. 接下来,图文解析IntelliJ IDEA如 ...

  8. java学习笔记--常用类

    一.Math类:针对数学运算进行操作的类 1.常用的方法 A:绝对值   public static int abs(int a) B:向上取整  public static double ceil( ...

  9. stl_hash_set.h

    stl_hash_set.h // Filename: stl_hash_set.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: ...

  10. HTTP协议状态代码和错误状态含义的解释

    面试互联网公司经常被问的就是HTTP协议的知识,甚至比TCP/IP问的还多,其中HTTP代码的知识也是开发过程中经常会接触的,今天学习所有 HTTP 状态代码及其定义. 代码  指示     2xx  ...