我刚接触Android开发。
目前,我在android客户端做注册功能。
我现在要做的只是将用户名和密码传递到JSP页面。但是当我尝试使用我的应用时,似乎没有将值传递给JSP
。
机器人:
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代码:
<%@ 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>
答案 0 :(得分:1)
您可以使用您的请求传递查询参数。在JSP中,您可以通过以下方式检索值:
<%= request.getParameter("name") %>
享受