Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing a file in a JSF app  RSS feed

 
J Miller
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

I have a JSF 1.2 application. What I'd like to do is, in my controller object, I'd like to write a JSON file that can be read by my web page. Problem is, I can't figure out how to write a file that my web app will be able to get to. Here's the folder structure of my project:

myProject
Java Resources
----src
--------bean (package)
--------controller (package)
------------ShipmentController.java (file doing the writing)
--------dao (package)
--------service (package)
WebContent
----data
--------trafficData.json (file to be written to)
----jsf


I'm looking at using the PrintWriter, but I've never used it before and I'm not sure how to write to that folder. Would using a relative location ("../../../WebContent/data/") work?
 
J Miller
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively, is there a better way to accomplish this? I have to create a JSON file for display in a grid.
 
J Miller
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind, I figured out a different solution.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you want to write the JSON data to a file? The more usual scenario would be to just send it as the response to some AJAX request which is about to fill in that grid.
 
J Miller
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly what I ended up doing. I always tend to think of the most difficult solution first
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's good. I was hoping not to have to answer the original question!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!