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

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

配置文件如下:

web.xml:

[html] view plaincopy print?
  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:

[html] view plaincopy print?
  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:

[html] view plaincopy print?
  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:

[java] view plaincopy print?
  1. public String execute() {
  2. // TODO Auto-generated method stub
  3. return SUCCESS;
  4. }

登陆页面 login.jsp:

[html] view plaincopy print?
  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:

[html] view plaincopy print?
  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也是可以的。不知道是什么问题,希望了解的大神们指点一下。

转载于:https://www.cnblogs.com/sharpest/p/5809853.html

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.comm ...

  3. struts2中报错404 No result defined for action com.jcrj.ahsfjd.ajgl.JdshAction and result input解决方法...

    今天写项目中遇到404 No result defined for action com.jcrj.ahsfjd.ajgl.JdshAction and result input错误,以前没有遇到过, ...

  4. No result defined for action

    有时候会碰到No result defined for action,可是我明明没啥问题啊.原因可能是以下几个: 1.Action中的属性值为空的时候,Struts2的默认拦截器会报错,但是又找不到i ...

  5. 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 ...

  6. 【SSH进阶】No result defined for action **的解决方案

    最近在做办公自动化的项目,用的框架是SSH,在SSH整合的时候遇到了这样的问题. No result defined for action cn.itcast.oa.view.action.RoleA ...

  7. Struts2 Problem Report: No result defined for action ... and result exception

    每    当Struts2爆出这样的异常,会很郁闷,原因太多了,只能一一的检查.有的说input页面没指定,有的说namespace有问题,有的说你对应的result有问题,有的说validate不通 ...

  8. struts2 上传文件 HTTP Status 404 - No result defined for action.....and result input

    2019独角兽企业重金招聘Python工程师标准>>> struts2 在使用jqeury Ajax上传文件时报HTTP Status 404 -  No result define ...

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

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

  10. struts2中No result defined for action xxx.xxx.xxx and result xxx错误的几种解决方法

    首先先说一下No result defined for action xxx.xxx.xxx and result xxx这个错误 action后跟的是你的action名称 result是返回值错误, ...

最新文章

  1. IEEE 754标准--维基百科
  2. bash shell脚本访问PostgreSQL的三种方式
  3. shared_ptr简介以及常见问题
  4. 华为鸿蒙宣传悟空视频_华为自研鸿蒙系统定档9月?《悟空》微电影透露玄机...
  5. 【luogu1018】 乘积最大 [区间dp+高精][noip2000]
  6. MinGW-w64 离线包安装方法
  7. idea英文翻译插件Translation
  8. 鸿鹄系统和鸿蒙系统的区别,华为鸿蒙系统和全新的鸿鹄处理器将于8月9日正式发布,荣耀首发...
  9. Oracle 11.2.0.4.0 安装包校验
  10. C/C++生成随机数
  11. LOJ#2538. 「PKUWC2018」Slay the Spire
  12. 【NOIP 2018 提高组】填数游戏
  13. InvalidDefinitionException: No serializer found for class java.lang.Object and no properties discove
  14. 程序员们,再不行动就来不及了!
  15. 谷歌pay服务端文档_米大师服务端说明
  16. Wormhole网站
  17. 这段温暖的路程谁能丈量
  18. c++类型转换:static_cast, dynamic_cast,const_cast和reinterpret_cast
  19. c语言实现作业调度算法实验报告,时间片轮转调度算法的实验报告.doc
  20. 无人机系列之飞控算法

热门文章

  1. 程序猿段子_【新年新气象】今年,能为程序员男友做点什么?
  2. java中堆栈(stack)和堆(heap)
  3. 命令行参数的模式匹配
  4. SQL Server,Oracle,DB2索引建立语句的对比
  5. aspnetboilerplate .net core 使用原生sql
  6. FL2440移植LINUX-3.4.2 -- 按键驱动和触摸屏驱动移植
  7. android 生命周期 Activity/Fragment lifecycle
  8. 搜索引擎学习(二)Lucene创建索引
  9. random(随机模块)
  10. C语言基本语法——函数