Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass value from Android to JSP

I am just new to the Android development. Currently, I am doing register function in android client. What I want to do now is just to pass the username and password into the JSP page. But when I tried on my app, it seems not passing the value into the JSP.

Android:

    public class RegisterActivity extends Activity {
    String url = "http://101.78.175.101:20281/test/useradd.jsp";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            setContentView(R.layout.registeractivity);
            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost(url);

            List<NameValuePair> pairs = new ArrayList<NameValuePair>();
            pairs.add(new BasicNameValuePair("uid", "hardik"));
            pairs.add(new BasicNameValuePair("pwd", "trivedi"));
            post.setEntity(new UrlEncodedFormEntity(pairs));
            client.execute(post);

            TextView mail = (TextView) findViewById(R.id.Register_mail);
            mail.setText("hello");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

JSP code:

<%@ page import="java.sql.*" %>

<%
String connectionURL = "jdbc:mysql://localhost:3306/xxx";
Connection connection = null;
Statement statement = null;
int insert_flag = 0 ;
%>

<html>
<body>
<% 
   String insert_sql ;
   String usermail, password; 
   usermail=request.getParameter("uid");  
   password=request.getParameter("pwd");  

Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "xxx", "xxx");
statement = connection.createStatement();

insert_sql = "insert into user ( usermail, userpassword ) values ( '" + usermail + "' , '" + password + "')" ; 
insert_flag = statement.executeUpdate( insert_sql );

if ( insert_flag > 0 ) out.println("record inserted") ;

%>
</body>
</html>
like image 810
Tianbing Leng Avatar asked Nov 23 '25 03:11

Tianbing Leng


1 Answers

You can pass Query parameters with your Request. In JSP you can retrieve the values by:

<%= request.getParameter("name") %>

Enjoy

like image 146
Goot Avatar answered Nov 24 '25 17:11

Goot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!