Javascript and Struts, question

  • Thread starter simplengrichard
  • Start date
S

simplengrichard

Hi!

We are currently developing an web application using the Jakarta
Struts framework (1.3). Since a lot of our forms involve date fields,
we used a javascript datepicker, a calendar displayed in a separate
window and the date picked is reflected on the textfield on the
original page. The javascript is located in an external js file.
When we access the page directly, as in localhost:8080/website/pages/
page.jsp, there is no problem. The datepicker works correctly.
However, if the page is accessed through a forward action localhost:
8080/website/ForwardToAction.do, a javascript error occurs. the
datepicker does not display in a new window. I viewed the error
console of firefox and its says that it is not defined. I do not know
what seems to be the problem. I am not sure but I was thinking that
because the page is accessed through a forward action then the html
head of the jsp page (where the script declaration for the javascript
is located) is not read. Thank you for your help.
 
E

Ed Webb

Hi!

We are currently developing an web application using the Jakarta
Struts framework (1.3). Since a lot of our forms involve date fields,
we used a javascript datepicker, a calendar displayed in a separate
window and the date picked is reflected on the textfield on the
original page. The javascript is located in an external js file.
When we access the page directly, as in localhost:8080/website/pages/
page.jsp, there is no problem. The datepicker works correctly.
However, if the page is accessed through a forward action localhost:
8080/website/ForwardToAction.do, a javascript error occurs. the
datepicker does not display in a new window. I viewed the error
console of firefox and its says that it is not defined. I do not know
what seems to be the problem. I am not sure but I was thinking that
because the page is accessed through a forward action then the html
head of the jsp page (where the script declaration for the javascript
is located) is not read. Thank you for your help.

I'm guessing that you have the line:

<script type="text/javascript" src="datepicker.js"/>

when the client requests the jsp page directly the browser is requesting:

localhost:8080/website/pages/datepicker.js

but when the client requests the action the browser is requesting:

localhost:8080/website/datepicker.js

because you have entered it as a relative url and the browser only knows
about the url it requested localhost:8080/website/ForwardToAction.do and
cannot possibly know that you redirected its request to a different file
in a different directory. One answer would be to make an absolute
reference to the javascript file in the jsp page. Maybe there are better
solutions.

Ed!
 
L

Luke Yan

another solution is to make your JSP and Action URL have the same URI.

for example, if your Action URL is "/website/pages/ForwardToAction.do"

~~~~~~~~~~~~~~~~
I believe problem you face to now there will be fixed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top