Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java Micro Edition
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Java Micro Edition
Connecting MIDlets to Servlets
Yavor lvanov
Greenhorn
Posts: 14
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi, this is very simple question turned into a headache for me.
I've got the following code on the server side:
import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class HitServlet extends HttpServlet { private int mCount; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String message = "Hits: " + ++mCount; response.setContentType("text/vnd.wap.wml"); response.setContentLength(message.length()); PrintWriter out = response.getWriter(); out.println(message); } }
And this is what my MIDlet looks like, a simple one again:
import java.io.*; import javax.microedition.io.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HitMIDlet extends MIDlet implements CommandListener { private Display mDisplay; private Form mMainForm; private StringItem mMessageItem; private Command mExitCommand, mConnectCommand; public HitMIDlet() { mMainForm = new Form("HitMIDlet"); mMessageItem = new StringItem(null, ""); mExitCommand = new Command("Exit", Command.EXIT, 0); mConnectCommand = new Command("Connect", Command.SCREEN, 0); mMainForm.append(mMessageItem); mMainForm.addCommand(mExitCommand); mMainForm.addCommand(mConnectCommand); mMainForm.setCommandListener(this); } public void startApp() { mDisplay = Display.getDisplay(this); mDisplay.setCurrent(mMainForm); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void commandAction(Command c, Displayable s) { if (c == mExitCommand) notifyDestroyed(); else if (c == mConnectCommand) { Form waitForm = new Form("Waiting..."); mDisplay.setCurrent(waitForm); Thread t = new Thread() { public void run() { connect(); } }; t.start(); } } private void connect() { HttpConnection hc = null; InputStream in = null; String url = "http://www.mobilekid.co.uk:8080/midp/hits"; try { hc = (HttpConnection)Connector.open(url); in = hc.openInputStream(); int contentLength = (int)hc.getLength(); byte[] raw = new byte[contentLength]; int length = in.read(raw); in.close(); hc.close(); // Show the response to the user. String s = new String(raw, 0, length); mMessageItem.setText(s); } catch (IOException ioe) { mMessageItem.setText(ioe.toString()); } mDisplay.setCurrent(mMainForm); } }
When I
test
it on the WTK 2.5 emulator it works fine, however, when deployed on my E61 I got a java.io.IOException -5105.
Your help and advices are much appreciated! Thank you!
Rashid Mayes
Ranch Hand
Posts: 160
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this may help. looks like the error is
tcpip6_error_NoRoute -5105 IPv6: No route available
from
http://newlc.com/article.php3?id_article=117
maybe the access point is not set up correctly.
Rashid Mayes
http://www.hostj2me.com/ -
http://www.worlddeveloper.org/
marimuthu kumaravel
Greenhorn
Posts: 1
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
private Command mExitCommand;
anyone explain this detail
no wonder he is so sad, he hasn't seen this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
J2ME and RMI or CORBA
Problem with servlet running on linux.
User-Agent is not being send + midlet
java lang ClassNotFoundException
Null URL Exception
More...