【问题标题】:jQuery not working with struts2 actionsjQuery 不适用于 struts2 动作
【发布时间】:2010-10-28 02:16:22
【问题描述】:

是否必须使用 struts2-jquery 插件才能在 struts2 应用程序中运行 jQuery 代码?

我正在开发一个 struts2 网络应用程序
jQuery 文件:WebContent/js/jquery-1.4.3.js
JSP页面位置:WebContent/pages/*.jsp

THDFindYourQuote.jsp 是应用程序的默认页面:
我在 THDFindYourQuote.jsp 中有一个简单的脚本
[script type="text/javascript" src="../js/jquery-1.4.3.js"][/script]
[script type="text/javascript"]
$(document).ready(function(){
alert('I am in the JSP code now!!');
});

当我访问 url 时执行上述脚本:
localhost:8081/CloseQuote/pages/THDFindYourQuote.jsp

当我访问 URL 时,相同的脚本不起作用:
localhost:8081/ CloseQuote/

我在其他 JSP 中遇到了同样的问题。当我使用完整路径 URL 访问 jsp 时,该脚本有效。当我使用操作 url 访问 jsp 时它不起作用..请帮助

【问题讨论】:

    标签: jquery jsp struts2


    【解决方案1】:

    是否必须使用 struts2-jquery 插件才能在 struts2 应用程序中运行 jQuery 代码?

    没有。我不使用那个插件,我在我所有的 Struts2 应用程序中都使用 jQuery。只需像在 PHP 应用程序、Ruby 应用程序等中一样将其包含在 UI 层中即可。

    看起来问题在于您使用的是相对 URL。尝试使用绝对值。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    相关资源
    最近更新 更多