I am not sure on how 开发者_JS百科to go about this but I have a game which I want to expand further and let the user submit the score with their name.
This will submit the score and name to a servlet which will add the details into an access database.
The score is of an int type.
Would be great if someone could show me how to do this, or point me in the right direction.
Thanks
In Android, just pass score and name as request parameters in URL.
String url = "http://example.com/servlet?score=" + score + "&name=" + URLEncoder.encode(name, "UTF-8");
// Connect the URL.
In the servlet, just access them as request parameters.
int score = Integer.parseInt(request.getParameter("score"));
String name = request.getParameter("name");
// Save them in DB.
See also:
- Executing a HTTP GET request with HttpClient in Android
- Servlets info page
- JDBC tutorial
精彩评论