public void registrarUsuario() { String dato = ""; JSONParser parser = new JSONParser(); try { while (true) { dato = dis.readUTF(); String usuario = ""; String contraseña = ""; String contra = ""; if (dato.equals("Usuario")) { while (true) { usuario = dis.readUTF(); if (usuario != null) { JSONObject user = new JSONObject(); user.put(usuario, null); FileWriter escribir = new FileWriter("texto.txt"); BufferedWriter bw = new BufferedWriter(escribir); PrintWriter pw = new PrintWriter(bw); pw.write(user.toJSONString()); pw.close(); bw.close(); while (true) { contra = dis.readUTF(); if (contra.equals("Contraseña")) { while (true) { contraseña = dis.readUTF(); if (contraseña != null) { Object obj = parser.parse(new FileReader("texto.txt")); JSONObject asignaPass = (JSONObject) obj; asignaPass.put(usuario, contra); FileWriter escribir2 = new FileWriter("texto.txt"); BufferedWriter bw2 = new BufferedWriter(escribir2); PrintWriter pw2 = new PrintWriter(bw2); pw2.write(asignaPass.toJSONString()); bw2.newLine(); pw2.close(); bw2.close(); break; } } break; } } break; } } break; } } } catch (Exception e) { } }
/** @see Servlet#service(ServletRequest request, ServletResponse response) */ public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String input_string = request.getParameter("text"); PrintWriter out = response.getWriter(); Query parsed_query = parse(input_string); // Wrong input format -> null returned in parse function if (parsed_query == null) { String message = "Unknown query format"; out.write(message.toCharArray()); } // correct input format else { String answer = handleQuery(parsed_query); out.write(answer); } }