views:

30

answers:

1

Is it a must to use the struts2-jquery plugin to be able to run jQuery code in a struts2 application?

I am working on a struts2 web app
jQuery file: WebContent/js/jquery-1.4.3.js
JSP pages location: WebContent/pages/*.jsp

THDFindYourQuote.jsp is the default page of the application:
I have a simple script in 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!!');
});

The above script is executed when i access the url:
localhost:8081/ CloseQuote/pages/THDFindYourQuote.jsp

the same script does not work when I access the URL:
localhost:8081/ CloseQuote/

I am having the same problem in other JSPs. The script works when i access the jsp using the full path URL. It does not work when I access the jsp with action urls ..please help

A: 

Is it a must to use the struts2-jquery plugin to be able to run jQuery code in a struts2 application?

No. I don't use that plugin and I use jQuery in all of my Struts2 applications. Just include it in the UI layer the same as you would in a PHP application, a Ruby application, etc.

It looks like the problem is that you are using relative URLs. Try using absolute ones.

Steven Benitez
Where do you suggest I use absolute URLs?
struts.xml: <action name="Try"> <result>/pages/trial.jsp</result> </action>pages folder is in WebContent directory.
http://localhost:8081/CloseQuote/pages/trial.jsp: WORKShttp://localhost:8081/CloseQuote/Try: Does not work ...
Thanks for pointing me in the right direction. I was using src="../js/jquery-1.4.3.js"in the script tag! thanks so much!!!!