These are chat archives for vik-y/Java

20th
May 2015
Vikas Yadav
@vik-y
May 20 2015 05:16
everyone online?
??
Daksh Varshneya
@dakshvar22
May 20 2015 06:19
'username': $('#addUser fieldset input#inputUserName').val(),
            'email': $('#addUser fieldset input#inputUserEmail').val(),
            'fullname': $('#addUser fieldset input#inputUserFullname').val(),
            'age': $('#addUser fieldset input#inputUserAge').val(),
            'location': $('#addUser fieldset input#inputUserLocation').val(),
            'gender': $('#addUser fieldset input#inputUserGender').val()
$.ajax({
            type: 'POST',
            data: newUser,
            url: '/users/adduser',
            dataType: 'JSON'
        })
Vikas Yadav
@vik-y
May 20 2015 07:18
<%@ page language="java" contentType="application/json; charset=UTF-8"
    pageEncoding="UTF-8"%>



<%@page import="java.io.*" %>
<%@page import="java.net.*" %>

<%
String t = request.getParameter("api");
if(t.equals("get_users")){
    String recv;
    String recvbuff = "";
    URL jsonpage = new URL("http://208.43.69.245:1649/users/userlist");
    HttpURLConnection connection = (HttpURLConnection)jsonpage.openConnection();
       connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

    connection.setRequestProperty("Content-Length", "" + 
               Integer.toString(urlParameters.getBytes().length));
      connection.setRequestProperty("Content-Language", "en-US");  

      connection.setUseCaches (false);
      connection.setDoInput(true);
      connection.setDoOutput(true);

      //Send request
      DataOutputStream wr = new DataOutputStream (
                  connection.getOutputStream ());
      wr.writeBytes (urlParameters);
      wr.flush ();
      wr.close ();
    BufferedReader buffread = new BufferedReader(new InputStreamReader(urlcon.getInputStream()));

    while ((recv = buffread.readLine()) != null)
        recvbuff += recv;
    buffread.close();
    out.println(recvbuff);
}
else if(t.equals("add_user")){
    out.println("adding user");
}
else if(t.equals("delete_user")){
    out.println("adding user");
}  
%>
Daksh Varshneya
@dakshvar22
May 20 2015 09:19
<%@ page language="java" contentType="application/json; charset=UTF-8"
    pageEncoding="UTF-8"%>



<%@page import="java.io.*" %>
<%@page import="java.net.*" %>
<%@page import="java.net.HttpURLConnection" %>
<%@page import="javax.net.ssl.HttpsURLConnection" %>
<%@page import="java.net.URL" %>
<%
String t = request.getParameter("api");
if(t.equals("get_users")){
   String recv;
   String recvbuff = "";
   URL jsonpage = new URL("http://208.43.69.245:1649/users/userlist");
   URLConnection urlcon = jsonpage.openConnection();
   BufferedReader buffread = new BufferedReader(new InputStreamReader(urlcon.getInputStream()));

   while ((recv = buffread.readLine()) != null)
       recvbuff += recv;
   buffread.close();
   out.println(recvbuff);
}
else if(t.equals("add_user")){
    out.println("adding user");
    String url = "http://208.43.69.245:1649/users/adduser";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    //add reuqest header
    con.setRequestMethod("POST");
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
    String username = request.getParameter("username");
    String email = request.getParameter("email");
    String fullname = request.getParameter("fullname");
    String age = request.getParameter("age");
    String location = request.getParameter("location");
    String gender = request.getParameter("gender");
    String urlParameters = "username="+username+"&email="+email+"&fullname="+fullname+"&age="+age+"&location="+location+"&gender="+gender;
    out.println(urlParameters);

    // Send post request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(urlParameters);
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();
    System.out.println("\nSending 'POST' request to URL : " + url);
    System.out.println("Post parameters : " + urlParameters);
    System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    String inputLine;
    //StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
    //    response.append(inputLine);
    }
    in.close();

    //print result
    //System.out.println(response.toString());
}
else if(t.equals("delete_user")){
    out.println("delete user");
}  
%>
Daksh Varshneya
@dakshvar22
May 20 2015 10:11
This message was deleted