This is my current Midlet
if (display.getCurrent() == mainform) {
selectedparam = activity.getString(activity.getSelectedIndex());
url = "http://localhost:8080/TOMCATServer/RetrieveServlet?";
parameter = "activity=" + selectedparam;
System.out.println(url + parameter);
try {
hc = (HttpConnection) Connector.open(url + parameter);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("CONTENT_TYPE", "application/x-www-from-urlencoded");
hc.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
out = hc.openOutputStream();
byte[] postmsg = parameter.getBytes();
for (int i = 0; i < postmsg.length; i++) {
out.write(postmsg[i]);
}
out.flush();
in = hc.openInputStream();
int ch;
while ((ch = in.read()) != -1) {
b.append((char) ch);
}
String result = b.toString().trim();
System.out.println(result);
activitiesform.deleteAll();
activitiesform.append(result);
display.setCurrent(activitiesform);
} catch (Exception c) {
Alert alert = new Alert("Error", "The connection has failed. Please try again.", null, AlertType.ERROR);
display.setCurrent(alert);
}
And this is my current Servlet
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String activityparam = request.getParameter("activity");
String[] sports = new String[5];
sports[0] = ("Football competition");
if (activityparam.equals("Sports")) {
out.println("These are the list of sporting activities \n");
for (int i = 0; i < 5; i++) {
out.println(sports[i]);
//Wanted to output the images of different sports here
}
What I wanted to achieve is that the Servlet could display an image back to the Midlet along with the string of sports[i], after the query request is sent. Right now, it is only dealing with String texts using PrintWriter. The image file is stored locally, so an absolute path should be fine. Please help me. Thanks.