• 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to pass data from client side to server side in Struts using javascript

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

I have a javascript function called "dostuff" (as shown below) that is called when I click on a hyperlink on my .jsp. I'm basically trying to pass some client side data in my textbox on my .jsp to my action using javascript . . . something like shown below. However, I'm not sure how to do this (or the syntax). Can someone assist me with this? Your help is much appreciated.



Thanks,

Rob
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not need to do pass any values explicitly - Struts takes care of that for you.

Here is some pseudo code -

JSP:


struts.xml:


InventoryBean:


There are several examples online - I found this when I searched for one now - Struts2 CRUD Example

Hope this helps.
 
Robert Wiscup
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sue,

Thank you for responding . . . but I'm using Struts 1 and not Struts 2.

Sorry I should have said so . . .

Thanks,

Rob
 
Sue Temple
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The outline holds good for Struts1 as well, with some syntax change.

Struts 1 Hello World

 
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

Robert Wiscup wrote:


Multiple issues. Here you're trying to use JavaScript inside Java, *and* you're setting an attribute in the *current* request. I'd suggest reading up on how web applications work before proceeding much further--you're due for tears and frustration without understanding the lifecycle of Java, JavaScript, HTTP requests, and the like.

The only way data gets from a browser to a server is via form submissions, XHR (Ajax) requests, etc.

@Sue: have a care regarding line length and weird formatting.
 
Robert Wiscup
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

Thanks for responding . . .

You can't really do what I was trying to do. As you said you can only get data from client to server via posting of a form and some other techniques . . . so I've rearranged things and everything is working fine now . . .

Thanks,

Rob
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic