No result defined for action action.LoginAction and result success 问题解决
转自:https://blog.csdn.net/dongzhout/article/details/43699699
搭建好SSH2框架,写一个简单的登陆功能,提交表单的时候遇到这个问题:
配置文件如下:
web.xml:
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="3.0"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
- <display-name></display-name>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- </filter-class>
- <init-param>
- <param-name>config</param-name>
- <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>*.action</url-pattern>
- </filter-mapping>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>*.jsp</url-pattern>
- </filter-mapping></web-app>
spring配置文件:applicationContext.xml:
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="3.0"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
- <display-name></display-name>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- </filter-class>
- <init-param>
- <param-name>config</param-name>
- <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>*.action</url-pattern>
- </filter-mapping>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>*.jsp</url-pattern>
- </filter-mapping></web-app>
struts2.1配置文件struts.xml:
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
- <struts>
- <constant name="struts.objectFactory" value="spring" />
- <package name="default" extends="struts-default" >
- <action name="userLogin" class="LoginAction">
- <result name="success">/success.jsp</result>
- <result name="input">/login.jsp</result>
- </action>
- </package>
- </struts>
LoginAction.java:
- public String execute() {
- // TODO Auto-generated method stub
- return SUCCESS;
- }
登陆页面 login.jsp:
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%@taglib prefix="s" uri="/struts-tags"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'login.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
- <body>
- This is my JSP page.
- <br>
- <s:form action="userLogin.action">
- <s:textfield name="username" label="用户名" />
- <s:password name="password" label="密码"></s:password>
- <s:submit type="button" value="登陆" />
- </s:form>
- </body>
- </html>
成功跳转页面 success.jsp:
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%@taglib prefix="s" uri="/struts-tags"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'success.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
- <body>
- This is my JSP page.
- <br> Welcome!
- <h5>
- <s:property value="username" />
- </h5>
- <br>
- <h6>
- <s:property value="password" />
- </h6>
- </body>
- </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 问题解决相关推荐
- HTTP Status 404 - No result defined for action com.csdhsm.struts.action.LoginAction and result error
智商拙计的问题,没有找到为类LoginAction和error找到定义,然后重新去struts.xml去看,我类个去,我居然把result写成了ERROR <result name=" ...
- Struts 2.x No result defined for action 异常
这是我跑struts2的第一个例子,跑的也够郁闷的,这个问题烦了我几个钟... 2011-5-10 10:10:17 com.opensymphony.xwork2.util.logging.comm ...
- 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错误,以前没有遇到过, ...
- No result defined for action
有时候会碰到No result defined for action,可是我明明没啥问题啊.原因可能是以下几个: 1.Action中的属性值为空的时候,Struts2的默认拦截器会报错,但是又找不到i ...
- 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 ...
- 【SSH进阶】No result defined for action **的解决方案
最近在做办公自动化的项目,用的框架是SSH,在SSH整合的时候遇到了这样的问题. No result defined for action cn.itcast.oa.view.action.RoleA ...
- Struts2 Problem Report: No result defined for action ... and result exception
每 当Struts2爆出这样的异常,会很郁闷,原因太多了,只能一一的检查.有的说input页面没指定,有的说namespace有问题,有的说你对应的result有问题,有的说validate不通 ...
- struts2 上传文件 HTTP Status 404 - No result defined for action.....and result input
2019独角兽企业重金招聘Python工程师标准>>> struts2 在使用jqeury Ajax上传文件时报HTTP Status 404 - No result define ...
- validators配置要点及No result defined for action报错解决方案
在做JavaEE SSH项目时,接触到validators验证. 需要了解validators配置,或者遇到No result defined for action 这个错误时,可查阅本文得到有效解决 ...
- 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是返回值错误, ...
最新文章
- IEEE 754标准--维基百科
- bash shell脚本访问PostgreSQL的三种方式
- shared_ptr简介以及常见问题
- 华为鸿蒙宣传悟空视频_华为自研鸿蒙系统定档9月?《悟空》微电影透露玄机...
- 【luogu1018】 乘积最大 [区间dp+高精][noip2000]
- MinGW-w64 离线包安装方法
- idea英文翻译插件Translation
- 鸿鹄系统和鸿蒙系统的区别,华为鸿蒙系统和全新的鸿鹄处理器将于8月9日正式发布,荣耀首发...
- Oracle 11.2.0.4.0 安装包校验
- C/C++生成随机数
- LOJ#2538. 「PKUWC2018」Slay the Spire
- 【NOIP 2018 提高组】填数游戏
- InvalidDefinitionException: No serializer found for class java.lang.Object and no properties discove
- 程序员们,再不行动就来不及了!
- 谷歌pay服务端文档_米大师服务端说明
- Wormhole网站
- 这段温暖的路程谁能丈量
- c++类型转换:static_cast, dynamic_cast,const_cast和reinterpret_cast
- c语言实现作业调度算法实验报告,时间片轮转调度算法的实验报告.doc
- 无人机系列之飞控算法
热门文章
- 程序猿段子_【新年新气象】今年,能为程序员男友做点什么?
- java中堆栈(stack)和堆(heap)
- 命令行参数的模式匹配
- SQL Server,Oracle,DB2索引建立语句的对比
- aspnetboilerplate .net core 使用原生sql
- FL2440移植LINUX-3.4.2 -- 按键驱动和触摸屏驱动移植
- android 生命周期 Activity/Fragment lifecycle
- 搜索引擎学习(二)Lucene创建索引
- random(随机模块)
- C语言基本语法——函数