1
我無法從我的jsp頁面中獲取android傳遞的值。我犯了錯誤。任何建議!將參數從android傳遞給servlet/jsp
下面是我的代碼:
==========================
客戶端:Android的活動
package org.test2;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class test2Activity extends Activity {
EditText ed;
Button ok;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ed=(EditText)findViewById(R.id.EditText01);
ok=(Button)findViewById(R.id.Button01);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpGet request=new HttpGet("http://localhost:8080/t5/jsp1.jsp?name=hiren");
//HttpPost httppost = new HttpPost("http://localhost:8080/t5/jsp1.jsp?name=hiren");
try {
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(request);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
}catch (IOException e) {
// TODO Auto-generated catch block
}
}
});
}
}
=======================================
服務器:JSP
<%@ page import="java.util.*" language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Parameter value =
<%=request.getParameter("name") %>
</body>
</html>
=========================================
爲什麼不在JSP中打印什麼?你怎麼知道你是否從Android獲取了某些東西! – 2011-01-11 09:38:04