Note that there are some explanatory texts on larger screens.

plurals
  1. POMy applet cannot connect to Servlet and transfering data
    text
    copied!<p>I want to send some data from my Applet to a specific Servlet which supposed to connect to a MySQL database and store the transferred data. In the Applet side I used this method to transfer data from applet to the servlet:</p> <pre><code> public void sendData() { try { URL postURL = new URL("http://localhost:8080/MyApplet/mydb"); HttpURLConnection conn = (HttpURLConnection) postURL.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.connect(); String param1 = "data1"; String param2 = "data2"; String param3 = "data3"; PrintWriter out = new PrintWriter(conn.getOutputStream()); out.write("param1=" + URLEncoder.encode(param1, "UTF-8") + "&amp;param2=" + URLEncoder.encode(param2, "UTF-8") + "&amp;param3=" + URLEncoder.encode(param3, "UTF-8")); out.flush(); } catch (Exception e) { System.err.println(e.getMessage()); JOptionPane.showMessageDialog(GameApplet.this, e.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE); } } </code></pre> <p>Which MyApplet/mydb is the path of my Selrvet. and in the Servlet side I wrote this code:</p> <pre><code> protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String parameter1 = request.getParameter("param1"); String parameter2 = request.getParameter("param2"); String parameter3 = request.getParameter("param3"); connectToDB(); insert(parameter1, parameter2, parameter3); // insert("X", "Y", "Z"); closeDB(); } </code></pre> <p>which <code>processRequest()</code> calls from <code>doGet()</code> and <code>doPost()</code>. The Servlet works properly when I call it directly from its http link and fill the database without any problem but when I call it from the applet , nothing happens and even without any exception! to be honest , they can't communicate with each other and I'm really confused.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload