Struts 2 JSON sample

Download my sample Struts 2 JSON sample war here.

I spent hours reading and googling around learning JSON on struts 2. Yes, there are many tutorials about this but i guess, there where no nonsense sample like a “war” file that you can just run. So, i made one. I know a lot of java programmers starting out Struts 2 and JSON are looking for this one.

Here’s what you should do:
1. Download this war.
2. On tomcat, put it on webapp folder
3. Run tomcat with your localhost like this: http://localhost:8080/struts2json/

That’s it! No-frills, simple JSON on Struts 2 sample. Struts 2 is really much more simplier than Struts 1. Its just that there’s fewer samples and tutorials in Struts 2 than 1, i dont know why. Hope, this’ll help you start out.

Please leave a comment or message me if i left out something.


update: included the java source code on the war file. sorry, i totally forgot. my bad :) you can look it up together with the class file. rock on!

Advertisement

39 Responses to “Struts 2 JSON sample”

  1. [...] on Struts 2 annotation. Im pretty lazy writing right now. Also, you might also be interested in my Struts 2 JSON sample if you are starting out on Struts [...]

  2. Thanks for your war file, I was googling half the day, but just getting a wrong message that tell me it can’t read a public method of Oracle when I used struts2 json plugin 0.3, maybe your setting can help me.
    thank you very much!

  3. can you post ur code here and elaborate more on ur problem? sorry for replying late, i got sick :(

  4. Direct to the point! Thanks for the help ;)

  5. This makes it much clearer. However how do you move objects that are not String objects. Do you have to define the objects in the Javascript portion?

    Thx

    Elan

  6. Elan, you could convert the object in javascript using the “eval()”. google it up. :)

  7. Narasimha Rao Konjeti Says:

    Very Quick tutorial for techies.

  8. Narasimha Rao Konjeti Says:

    Great man, let me know, I fyou have more example like this.

  9. Very concise and working examples. Thanks.

    One feature that I would love to see is binding incoming JSON values. That would complete the example.

  10. Moacir RF Says:

    Great Tutorial!!! thanks…
    I was need it!!

    Sorry my bad english!

    Im Brazilian…
    hehehe

  11. tats qool, thanks man..

  12. Where to find source code of this war? ..I want code

    • use 7zip or winrar or something else to uncompress the war file. You can find the source code inside. Good luck :)

  13. Good and elegant struts2 code… i love your war… :)

  14. Muthukumar Says:

    Hi,

    I have got an error tat IllegalAccessException:

    java.lang.IllegalAccessException: Class com.googlecode.jsonplugin.JSONWriter can not access a member of class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers “public”

  15. K R Arun Raaj Says:

    I don find the method getJSON implemented in the source code.. could you please give me a clear view on this issue… I am actually in urgent need to work with struts and json. If you don mind , can i get your full source code , so that i learn them clearly

  16. Hi,

    Thank you for your nice example.
    Do you have a similar example on binding incoming JSON values?

  17. Amazing because its so simple and small. I am using Struts 2.1.8 and it still works as is without any additional changes!!

    Thanks for a simple example without all the stupid crap that most examples on this topic have added. And thanks for not showing DOJO but using the simple prototype js library. Its lightweight and gets the job done!

    Thanks again.
    SK

  18. thank 100% working

  19. Yeah! thanx man!

  20. very helpfull for me. :)
    thx man.

  21. thanks for your war its very heplfull for me :)

  22. BEST tutorial ever, I’ve spent all day looking for a tutorial like this one, THANKS!!!

  23. Thangaprabhu Says:

    Great Work. Saves a time lot

  24. Nice attempt. you make me lazy too!

  25. Nice mate!
    like it!

    @: to Other readers, please also look at the apache struts2 Tutorial for the rule of JSON!!!

    Gambatte all !! :)

  26. If my package extends hibernate-default and i add json-default my application isn’t working. Do you have any suggestions?
    Thank you!

  27. hi I have created my own sample based from this :D thanks
    http://justlikeinschool.blogspot.com/2010/06/struts-2-and-jquery-without-fuss.html

  28. I just wanted something simple to show me the basics of how json works and is this was exactly what I was looking for.

    THANKS!

  29. Thanks a lot…u saved my life.

  30. Hi,
    I am trying to run this war file but nothing to do.. Sorry but I am very new to struts. I was trying to implement json with struts. Can i have the source code of this sample please?. I really need to have an executable sample
    thnx, Ester

  31. good one.
    wondering why the action is invoked twice.
    the “SampleList” printed twice. happens if u run in any browsers.

    thanks,
    rj

  32. juan hesse Says:

    Hello, I deployed your war and it run fine but when I click the button I just can see an alert saying “sTIKIFLEM sample” 1, 2, 3… but nothing about json sintax. Please let me know what I am doing wrong.
    Thx in advance.

    Juan

  33. Thanks a lot!! as you said that is what I was looking for.
    Good job1

  34. Dude , Its really saved my Time Thanks for such a nice demo

  35. Thanks, we need more examples like this to kick start the learning process. It is great, simple, straight forward example

  36. Budi Satrio Says:

    thank you! your very helpful :D

  37. You saved my life….. you simply rock!!!!! God bless :)

  38. Best website to search fot this software is for me FreePlatinumDownloads….

    [...]Struts 2 JSON sample « stikiflem’s techblog[...]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.