package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Archivos.RegresarUsuarios;
import Archivos.Usuario1;
import java.util.ArrayList;
import org.json.simple.*;

public class RegresarUsuariosServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String e = request.getParameter("username");
        
        ArrayList<Usuario1> u = RegresarUsuarios.validate(e);
        if (u!=null) {
            String format = request.getParameter("format");
            
            if (format.equals("json")) {
                JSONObject json = new JSONObject();
                json.put("success", true);
                
                    JSONObject user = new JSONObject();
                for (int i = 0; i < u.size(); i++) {
                    user.put("idUsuario", u.get(i).getidUsuario());
                    user.put("usuario", u.get(i).getidUsuario());
                    user.put("password", u.get(i).getPassword());
                    user.put("nickname",u.get(i).getNickname());
                    user.put("email", u.get(i).getEmail());
                    user.put("status",u.get(i).getStatus());
                    json.put("user", user);
                    out.print(user);
                }             
                    
            }
        } else {
            String format = request.getParameter("format");
            if (format.equals("json")) {
                JSONObject json = new JSONObject();
                json.put("success", false);
                json.put("message","ERROR");
                out.print(json);
               
                
            }

        }

        out.close();
    }
}

@@ -983,29 +983,16 @@
 rmat%22);%0A
-            %0A
         
@@ -1020,37 +1020,24 @@
 (%22json%22)) %7B%0A
-             
    JSONObjec
@@ -1059,37 +1059,24 @@
 ONObject();%0A
-             
    json.put(
@@ -1100,57 +1100,27 @@
 %0A   
-             %0A                    JSONObject
+%0A   JSONArray
  user
+s
  = n
@@ -1126,39 +1126,25 @@
 new JSON
-Object();%0A             
+Array();%0A
    for (
@@ -1174,34 +1174,61 @@
 ; i++) %7B%0A   
-          
+%09JSONObject user = new JSONObject();%0A
        user.
@@ -1266,37 +1266,24 @@
 Usuario());%0A
-             
        user.
@@ -1319,37 +1319,24 @@
 Usuario());%0A
-             
        user.
@@ -1372,37 +1372,24 @@
 assword());%0A
-             
        user.
@@ -1424,37 +1424,24 @@
 ickname());%0A
-             
        user.
@@ -1471,37 +1471,24 @@
 etEmail());%0A
-             
        user.
@@ -1530,26 +1530,39 @@
 %0A       
-          
+users.add(user);%0A   %7D%0A%0A
    json.
@@ -1574,119 +1574,40 @@
 user
+s
 %22, user
+s
 );%0A   
-                 out.print(user);%0A                %7D             %0A                    %0A            
+out.print(json);%0A
 %7D%0A  

Revert "Revert "CorreccionJSON""