action跳转过后,jquery失效

来源:互联网 发布:mac mini 更新 编辑:程序博客网 时间:2024/06/06 02:08

当你在某个jsp页面跳转到action执行操作以后,再返回页面发现css和js全部失效,要刷新才能重新加载


问题原因在于action跳转回来以后的目录路径是你的action所配置的目录


解决方法就是把Jsp中所有的相对路径改成绝对路径 


原来的写法

<script type="text/javascript" src="../../../../../common/webui/jquery-1.7.2.min.js"></script>

首先增加绝对根路径,然后再把相对路径改成绝对路径修改后的写法,

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib uri="/struts-tags" prefix="s" %><%@ taglib prefix="sd" uri="/struts-dojo-tags" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>guiding demo</title><script type="text/javascript" src="<%=basePath%>common/webui/jquery-1.7.2.min.js"></script> <script type="text/javascript">      $(function(){      $("#hospitalid").attr('value','2234');      });    </script></head>



0 0
原创粉丝点击