转自: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. SQl查询基础

    SQL语言是一门简单易学却又功能强大的语言,他让你快速上手并写出比较复杂的查询语句,但对于大多数开发者来书,使用SQL查询数据库并没有一个抽象的过程和一个合理的步骤,这很可能会是在写一些特定的查询语句 ...

  2. review19

    StringBuffer类 String类创建的字符串对象是不可修改的,也就是说,String字符串不能修改.删除或替换字符串中的饿某个字符,即String对象一旦创建,那么实体是不可以再发生变化的. ...

  3. Jedis使用过程中踩过的那些坑

    1. 一个 大坑:若实例化 JedisShardInfo 时不设置节点名称(name属性),那么当Redis节点列表的顺序发生变化时,会发生“ 键 rehash 现象” 使用BTrace追踪redis ...

  4. java: Comparable比较器,定义二叉操作类

    //定义二叉操作类 class BinaryTree{ class Node{ private Node left; //左指数 private Node right; //右指数 private C ...

  5. ADO.NET入门教程(一) 初识ADO.NET

    摘要 作为.NET框架最重要的组件之一,ADO.NET扮演着应用程序与数据交互的重要的角色.本文将从宏观的角度来探讨ADO.NET,和大家一起了解ADO.NET来龙去脉以及ADO.NET的主要组成部分 ...

  6. Educational Codeforces Round 33 (Rated for Div. 2)A-F

    总的来说这套题还是很不错的,让我对主席树有了更深的了解 A:水题,模拟即可 #include<bits/stdc++.h> #define fi first #define se seco ...

  7. node.js 操作excel

    首先安装依赖库node-xlsx npm install node-xlsx 在操作文件中直接引用 var xlsx = require("node-xlsx"); 读取excel ...

  8. LeetCode OJ:Count and Say(数数)

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  9. LeetCode OJ:Contains Duplicate(是否包含重复)

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  10. 2017.11.28 Enginering management:problem-solving ability

    Today,my colleague is on bussiness trip. going to customer factory in jiangxi. slove the color diffe ...