action无法跳转,表单无法跳转的解决方法

刚在网上搜索了一下,发现我的这篇文章已被非常多人转载了去其他站点。暗爽,只是还是希望大家注明出处。

顺便说明一下。下面是在struts2中通过測试的

action无法跳转、表单无法跳转的原因:
说明 :在确保你项目的其他action、表单能正常跳转的情况下,查找下面3个原因。
1、确认action中有无写错,struts中有无指定action的class
如:<action name="*User" class="com.login.action.LoginAction" method="{1}">,假设后台java中没有这里class指定的路径,那么将无法跳转
2、表单有没有后缀,如指定后缀是action,则一定要配置  <url-pattern>*.action</url-pattern>或<url-pattern>/*</url-pattern>
3、form表单中的action是否可以与struts.xml里action的name匹配
如:jsp表单<form action="saveUser.action" id="infoForm"
method="post">,假设在struts.xml找不到<action name="*User" class=" ####  ">(这里的*User,*是通配符)或<action name="saveUser" class=" ####  ">,将无法跳转

jsp form表单中的action无法跳转
假设表单中action中没有后缀,使用   <url-pattern>*.action</url-pattern> 这样的配置将无法跳转,由于匹配不了后缀名。

 使用 <url-pattern>*.action</url-pattern> 时

如:
1、
<form action="saveChild.action" id="infoForm" method="post">  action有后缀名,这样的能正常跳转
2、<form action="saveChild" id="infoForm"
method="post">  action没有后缀名,无法跳转
但假设使用   <url-pattern>/*</url-pattern> 在表单中即使action中没有后缀名,即<form action="saveChild" id="infoForm" method="post">。也能跳转
假设表单正常跳转,控制台应该会打印出这种方法。如:
2014-05-06 12:11:52,404 DEBUG (org.apache.struts2.interceptor.FileUploadInterceptor:68) - Bypassing //saveChild
2014-05-06 12:11:52,407 DEBUG (org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor:68) - Validating //saveChild with method save.
依据我自己的经验,假设控制台没有打印出“Bypassing // action名”,那么表单的action都是无法正常跳转到后台的
 <url-pattern>/*</url-pattern>
使用 <url-pattern>/*</url-pattern>这样的会将servlet拦截了,假设项目中有单独创建的servlet。那么将无法訪问这个servlet,如平时使用servlet创建一个验证码的链接
所以假设要使用验证码的servlet,那么就将使用下面这样的配置了
 <filter-mapping>
    <filter-name>struts</filter-name>
    <url-pattern>*.action</url-pattern>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>
jsp訪问时,无法訪问
假设仅仅定义了   <url-pattern>*.action</url-pattern>;而未定义 <url-pattern>*.jsp</url-pattern>。那么jsp也将无法訪问
一个通过測试的web.xml文件。没有给出web.xml文件头,由于包括了url,博客不准发url
  <display-name>unionweb</display-name>
   
  <!-- 监听器,整合spring中使用 -->
   <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
 
  <!-- spring的 applicationContext.xml文件存放路径,类路径-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
 
  <!-- 下面是struts2的过滤器的配置 -->
  <filter>
    <filter-name>struts</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
 
  <filter-mapping>
    <filter-name>struts</filter-name>
      <!--
    <url-pattern>/*</url-pattern>
       -->
    <url-pattern>*.action</url-pattern>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
 
说明:以上所有都是我自己经过測试的,如说的不正确。还望大家指出 

javaweb action无法跳转、表单无法跳转的解决方法的更多相关文章

  1. mysql表单输入数据出现中文乱码解决方法

    MySQL会出现中文乱码的原因在于1.server本身设定问题,一般来说是latin1 2.建库建表时没有制定编码格式. 解决方法: 1.建库的时候 CREATE DATABASE test CHAR ...

  2. PHP一个表单多个提交按钮解决方法

    1.html页面<注:多个按钮的name值必须相同> <form action="{:U('Index/index')}" method="post&q ...

  3. jQuery Validate 表单验证插件----自定义一个验证方法

    一.下载依赖包 网盘下载:https://yunpan.cn/cryvgGGAQ3DSW  访问密码 f224 二.引入依赖包 <script src="../../scripts/j ...

  4. JavaWeb(十三)——使用Session防止表单重复提交

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...

  5. javaweb基础(13)_session防止表单重复提交

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...

  6. asp.net.mvc 中form表单提交控制器的2种方法和控制器接收页面提交数据的4种方法

    MVC中表单form是怎样提交? 控制器Controller是怎样接收的? 1..cshtml 页面form提交 (1)普通方式的的提交

  7. jquery validate表单验证插件的基本使用方法及功能拓展

    1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家.    1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素 3.鼠标离开后的正确.错误提示及鼠标移入时的帮助提 ...

  8. jQuery实现form表单基于ajax无刷新提交方法详解

    本文实例讲述了jQuery实现form表单基于ajax无刷新提交方法.分享给大家供大家参考,具体如下: 首先,新建Login.html页面: <!DOCTYPE html PUBLIC &quo ...

  9. jQuery 表单元素取值与赋值方法总结

    一.普通文本框的赋值与取值 1.1.1赋值 <h2>jQuery 表单元素取值与赋值方法总结</h2> <input type="text" clas ...

随机推荐

  1. IOC容器Autofac

    //类ContainerBuilder中的方法: RegisterType<T>()//注册类型T AsImplementedInterfaces()//表示注册的类型,以接口的方式注册 ...

  2. android studio - 隐藏编辑器标签块上面的索引

  3. WCF信道工厂Channel Factory

    ChannelFactory<TChannel> 类 一个创建不同类型通道的工厂,客户端使用这些通道将消息发送到不同配置的服务终结点. 命名空间: System.ServiceModel ...

  4. Introdution to Spring Mobile

    1. In Eclipse, create a new Maven Project using the spring-mvc-jpa-archetype. 2. Add the spring-mobi ...

  5. Leetcode392. Is Subsequence

    Description Given a string s and a string t, check if s is subsequence of t. You may assume that the ...

  6. 2017-5-14 湘潭市赛 Highway 先获得直径S,T。则一开始S,T相连,然后其他的点如果离S更远那么连在S,否则T;

    Highway Accepted : Submit : Time Limit : MS Memory Limit : KB Highway In ICPCCamp there were n towns ...

  7. VMware虚拟机 Ubuntu 实用技巧 (1) -- 安装VMware Tool

    1.用VM安装Ubuntu后屏幕太小? 2.Ubuntu中的文本与window中的文本不能互相复制黏贴? 如果你遇到以上问题,可以通过在VMware里安装“VMware Tool”插件解决!! 安装步 ...

  8. kdump 的使用在linux崩溃时

    Centos7/RHEL7 开启kdump 翻译 2017年12月18日 16:58:28 标签: kernel / kdump / crash / centos 437 原文链接<How to ...

  9. MySQL 5.7以上 root用户默认密码问题

    废话少说一句话系列: CentOS系统用yum安装MySQL的朋友,请使用 grep "temporary password" /var/log/mysqld.log 命令,返回结 ...

  10. Vsphere日记03.ESXi5.5.client

    3.Vsphere ESXi 5.5 client Vsphere Client介绍 1.Vsphere Client定义 Vsphere client隶属于Vsphere套件,主要用于远程管理ESX ...