I am using Eclipse Indigo and Tomcat 7.0. I have a Swing application, project “Controller” with package “gui”. With this application, I am creating a controller-tool for “setting” machine informations. I have several hashmaps, where the information of the Swing-elements are stored (20 similar panels, but containing different informations, like name, status, etc.).
I wanted to use a servlet to create a JSON file, containing these infos (I have to get the data somehow to my android application, and for me it JSON seemed a good choice). My servlet can be connected via localhost:8080/CommunicationBase/JSONServlet That’s where I have my problems: I cannot use my Swing application in the Dynamic-Web-Service project of my servlet.
A little example of my servlet:
public class JSONServlet extends HttpServlet {
/*this is in my dynamic-web-service-project "CommunicationBase" */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
JSONArray arrayObj = new JSONArray();
arrayObj.add("Machine #1");
arrayObj.add("Status: Down");
PrintWriter out = response.getWriter();
out.println(arrayObj);
arrayObj = new JSONArray();
arrayObj.add("Machine #2");
arrayObj.add("Status: Running");
}
}
How can I put my hashmap informations from the Swing application to the Servlet? Can I create just a single Java class into my “Controller” project, and add a web.xml? If yes, where? Or how do I do that?
Can I also change the JSON information of the servlet from my Android app then somehow easily? So that the information in my Swing application will change (Android and Swing application will always work in the same LAN).
Android Client:
Swing Application:
did the job. thx for your help!