• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

document.form.action problem

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a text box. I want to call an action class once i enter some value inside the text box and move my mouse out of the text box.

When i try to run the code, i get an error message saying /challan.do is not available.

Entry in struts-config:

<action path="/challan" type="ActionClass.ViewChallanAction" parameter="method" name = "ViewChallanForm" >
<forward name="success" path="/pages/viewchallan.jsp"></forward>
<forward name="next" path="/pages/challanentryB2B.jsp"></forward>
</action>


i tried the following, but failed:

<td >
<html:text name = "Products" property="nos_BL" size="7" onmouseout="calcBBSeries();" ></html:text>
</td>

function calcBBSeries()
{
document.forms[0].action = "/challan.do?method=calcBBSeries";
document.forms[0].submit();
}

Am i doing anything wrong?
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a 100% on this but when you say document.forms[0].action = "/challan.do?method=calcBBSeries";
the web browser consider the link to be relative to the root of the domain name.
Hence if your link is something like, http://MyIP/Application/currentPage.do
then instead of hitting the link http://MyIP/Application/challan.do it hits http://MyIP/challan.do which might result in a Page not found.

Can you post the URL of the page that shows up in the browser when the page submits?

Alternately you can try removing the "/" from document.forms[0].action = "/challan.do?method=calcBBSeries"; and see if that helps!
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:Not a 100% on this but when you say document.forms[0].action = "/challan.do?method=calcBBSeries";
the web browser consider the link to be relative to the root of the domain name.
Hence if your link is something like, http://MyIP/Application/currentPage.do
then instead of hitting the link http://MyIP/Application/challan.do it hits http://MyIP/challan.do which might result in a Page not found.

Can you post the URL of the page that shows up in the browser when the page submits?

Alternately you can try removing the "/" from document.forms[0].action = "/challan.do?method=calcBBSeries"; and see if that helps!



Hey, I tried removing '/' from action ,but didnt work.

I also tried the first option, i.e. i gave the entire url :http://localhost:8080/struts-blank/challan.do?method=calcBBSeries and it worked.

But can i get the url through some method, since if in future i change my application folder, i will have to change the url mechanically.

Thanks for your timely help. I was going mad searching for a solution
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Let me take a point blank guess here. Are you displaying a JSP/HTML page directly?

What I mean is, is your URL of the page from where you are calling the document.forms[0].submit(); something like this --> http://localhost:8080/struts-blank/jsp/index.jsp or something like this http://localhost:8080/struts-blank/home.do

Posting the URL of the page from which you are making the call would help.
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:Ok Let me take a point blank guess here. Are you displaying a JSP/HTML page directly?

What I mean is, is your URL of the page from where you are calling the document.forms[0].submit(); something like this --> http://localhost:8080/struts-blank/jsp/index.jsp or something like this http://localhost:8080/struts-blank/home.do

Posting the URL of the page from which you are making the call would help.



Hi,
I am not directly calling the jsp page. I am calling an action class.

URL : document.forms[0].action = "http://localhost:8080/struts-blank/challan.do?method=calcBBSeries";

Thanks.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should probably create the link using the Struts link tag, giving it the action you're submitting to.
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:You should probably create the link using the Struts link tag, giving it the action you're submitting to.



Hi,
I am calling that action from onchange of my <html:text>. I dont want it to appear as a link. Hence have not used <html:link>.


 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the link of the page where this form is displayed.

I know that the link of the page that you want to redirect to is http://localhost:8080/struts-blank/challan.do?method=calcBBSeries? My question is what is the link of the page from which this action is happening?
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:What is the link of the page where this form is displayed.

I know that the link of the page that you want to redirect to is http://localhost:8080/struts-blank/challan.do?method=calcBBSeries? My question is what is the link of the page from which this action is happening?



Hi,
Sorry i couldn't get your question earlier.
Well the link from where i am calling the action is:

http://localhost:8080/struts-blank/challan.do?method=getProducts

Thanks
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The construct

document.forms[0].action = "http://localhost:8080/struts-blank/challan.do?method=calcBBSeries"
or
document.forms[0].action = "challan.do?method=calcBBSeries" (without the front slash)

are the same from the way your application is structured. So both should work in the same manner.


The problem here is that you cannot pass a parameter using a query string when you do a document.forms[0].action which basically means that the parameter you pass 'method' would be lost on both cases. You will need to use hidden text to pass the parameter method to your 'challan.do' page.

I am surprised that the construct "http://localhost:8080/struts-blank/challan.do?method=calcBBSeries worked for you. It should work exactly in a similar manner to what happens when you do "challan.do?method=calcBBSeries". You could tell what is happening by changing the form[0] method to a 'Get' and looking at the URL in the web browser when the onchange event happens.

@Bear - This is a Java Script problem - I think it was in the correct forum initially - Just me thoughts.
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:
. You could tell what is happening by changing the form[0] method to a 'Get' and looking at the URL in the web browser when the onchange event happens.

.



Hey,
I tried changing the form method to 'GET'. But i get an error saying:
The request sent by the client was syntactically incorrect (Request[/challan] does not contain handler parameter named method).

URL: http://localhost:8080/struts-blank/challan.do?nos_BL=12&BL=Select
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deeps Mistry wrote:
Hey,
I tried changing the form method to 'GET'. But i get an error saying:
The request sent by the client was syntactically incorrect (Request[/challan] does not contain handler parameter named method).

URL: http://localhost:8080/struts-blank/challan.do?nos_BL=12&BL=Select



Exactly as you can see from the URL being send there is no parameter called 'method'. There are just two parameters being passed namely nos_BL and BL.

To pass the parameter method as part of the form you will need to use a hidden variable <input type='hidden' name='method'> in the form[0] & set its value to 'calcBBSeries' using JavaScript just before the step where you do document.forms[0].action = "/challan.do?method=calcBBSeries";

Hope this makes sense ...

P.S : Is the code working when you give the full URL i.e. http://localhost:8080/struts-blank/challan.do?method=calcBBSeries and method is POST?
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:

To pass the parameter method as part of the form you will need to use a hidden variable <input type='hidden' name='method'> in the form[0] & set its value to 'calcBBSeries' using JavaScript just before the step where you do document.forms[0].action = "/challan.do?method=calcBBSeries";



P.S : Is the code working when you give the full URL i.e. http://localhost:8080/struts-blank/challan.do?method=calcBBSeries and method is POST?



Hi,
Yes the code is working fine with full URL and method = "post".

I tried what you said:
<html:hidden name="ViewChallanForm" property="method" value=""/>

function calcBBSeries(product)
{

document.forms[0].method.value = calcBBSeries;
document.forms[0].action = "/challan.do?method=calcBBSeries";
//document.forms[0].action = "http://localhost:8080/struts-blank/challan.do?method=calcBBSeries";

document.forms[0].submit();
}

But its giving me the previous error: The requested resource (/challan.do) is not available.
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code is correct except for the URL which should be,
document.forms[0].action = "challan.do"; i.e the URL without the '/'

In case it does not work, you could repeat the previous step to change the 'Post' to 'Get' and see the URL thats being called. The URL should be http://localhost:8080/struts-blank/challan.do?nos_BL=12&BL=Select&method=calcBBSeries. If its not post the URL that you are getting.

Pretty long thread eh:)
 
Deeps Mistry
Ranch Hand
Posts: 189
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
document.forms[0].method.value = calcBBSeries;

You need to put calcBBSeries in double quotes, it should read
document.forms[0].method.value = "calcBBSeries";

What you are currently doing is assigning document.forms[0].method the value of the variable calcBBSeries which incidentally is the name function ... and that's what you get in your url...Once you put "calcBBSeries" in double quotes you'll see all your problems solved! (Hopefully )

 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:document.forms[0].method.value = calcBBSeries;

You need to put calcBBSeries in double quotes, it should read
document.forms[0].method.value = "calcBBSeries";

What you are currently doing is assigning document.forms[0].method the value of the variable calcBBSeries which incidentally is the name function ... and that's what you get in your url...Once you put "calcBBSeries" in double quotes you'll see all your problems solved! (Hopefully )



No not yet solved
By doing document.forms[0].method.value = "calcBBSeries"; what are we achieving? We are not setting it in the action.
What we are doing is :document.forms[0].action = "challan.do?method=calcBBSeries";

Totally confused
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok let me explain.

document.forms[0].action = "challan.do?method=calcBBSeries statement is actually incorrect. A form submit action should not contain a parameter to be passed to the server, basically it should not contain a query string.

That's the reason when you use a Get the parameters are overwritten and you don't see it getting passed as part of the query string.
When you use a post the form in incorrectly getting submitted with query string parameters. A Post request should not have any query string parameters. This is the reason why it is working with a POST and not a GET. However this is still incorrect and may break on a different browser.

By setting a form variable like document.forms[0].method.value = "calcBBSeries"; what happens is when the form is submitted all the form variable are either submitted to the server as
1. Post - Inside the body of the request
2. Get - As a query string.
Hence the value of 'method' becomes available to the server in the form Bean.

As always the only ways we can know whats going wrong is if you post more code or give the Get and Post URL as in the previous posts...

 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:Ok let me explain.

document.forms[0].action = "challan.do?method=calcBBSeries statement is actually incorrect. A form submit action should not contain a parameter to be passed to the server, basically it should not contain a query string.

That's the reason when you use a Get the parameters are overwritten and you don't see it getting passed as part of the query string.
When you use a post the form in incorrectly getting submitted with query string parameters. A Post request should not have any query string parameters. This is the reason why it is working with a POST and not a GET. However this is still incorrect and may break on a different browser.

By setting a form variable like document.forms[0].method.value = "calcBBSeries"; what happens is when the form is submitted all the form variable are either submitted to the server as
1. Post - Inside the body of the request
2. Get - As a query string.
Hence the value of 'method' becomes available to the server in the form Bean.

As always the only ways we can know whats going wrong is if you post more code or give the Get and Post URL as in the previous posts...



I am getting the same URL which i posted earlier.

Sam, cant we take the path from request(may be from some properties file) and append it to the action. So changes done at one place would be reflected at all other places. wat say?


 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its pretty strange that when you put quotes around "calcBBSeries" you still get the old URL ->
http://localhost:8080/struts-blank/pages/challan.do?method=function+calcBB...D&nos_BL=23&BL=Select
That's pretty weird!

Yes you could put the URL in a properties file and get it to be read from there. And yes that might solve your problem.

But it would still not be the correct way of doing it - A request having both Get and Post parameters is really strange! But I'm really out of answers at the moment, maybe somebody could spot what I am missing out on



 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant use the rewrite tag (I didn't mean the actual *link* tag) to generate the URL so you just specify the action.
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:I meant use the rewrite tag (I didn't mean the actual *link* tag) to generate the URL so you just specify the action.



Could you please explain it in simple words or with an example?

Thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic