The jsonpstreaming Example Application
This section describes how to build and run the jsonpstreaming example
application. This example is a web application that demonstrates how to
create JSON data from form data, how to parse JSON data, and how to
write JSON output using the streaming API.
The jsonpstreaming example application is in the
tut-install`/examples/web/jsonp/jsonpstreaming` directory.
The following topics are addressed here:
Components of the jsonpstreaming Example Application
The jsonpstreaming example application contains the following files.
-
Three JavaServer Faces pages.
-
The
index.xhtmlpage contains a form to collect information. -
The
filewritten.xhtmlpage contains a text area that displays JSON data. -
The
parsed.xhtmlpage contains a table that lists the events from the parser.
-
-
The
StreamingBean.javamanaged bean, a session-scoped managed bean that stores the data from the form and directs the navigation between the Facelets pages. This file also contains code that uses the JSON streaming API.
Running the jsonpstreaming Example Application
This section describes how to run the jsonpstreaming example
application using NetBeans IDE and from the command line.
The following topics are addressed here:
To Run the jsonpstreaming Example Application Using NetBeans IDE
-
Make sure that GlassFish Server has been started (see Starting and Stopping GlassFish Server).
-
From the File menu, choose Open Project.
-
In the Open Project dialog box, navigate to:
tut-install/examples/web/jsonp -
Select the
jsonpstreamingfolder. -
Click Open Project.
-
In the Projects tab, right-click the
jsonpstreamingproject and select Run.This command builds and packages the application into a WAR file (
jsonpstreaming.war) located in thetargetdirectory, deploys it to the server, and opens a web browser window with the following URL:http://localhost:8080/jsonpstreaming/ -
Edit the data on the page and click Write a JSON Object to a File to submit the form and write a JSON object to a text file. The following page shows the contents of the text file.
-
Click Parse JSON from File. The following page contains a table that lists the parser events for the JSON data in the text file.
To Run the jsonpstreaming Example Application Using Maven
-
Make sure that GlassFish Server has been started (see Starting and Stopping GlassFish Server).
-
In a terminal window, go to:
tut-install/examples/web/jsonp/jsonpstreaming/ -
Enter the following command to deploy the application:
-
Open a web browser window and enter the following URL:
http://localhost:8080/jsonpstreaming/ -
Edit the data on the page and click Write a JSON Object to a File to submit the form and write a JSON object to a text file. The following page shows the contents of the text file.
-
Click Parse JSON from File. The following page contains a table that lists the parser events for the JSON data in the text file.