servlet与J2me Project进行通信? [英] servlet communicate with J2me Project?
问题描述
我正在使用Eclipse在J2ME中开发一个应用程序。在这个应用程序中,我正在使用一个名为HitServlet的Servlet和一个J2me Class HitMIDlet。
我想使用Eclipse运行这个项目。但是我不是目录结构
以及我如何创建目录结构。
我在我的eclipse中配置了J2ME插件和Tomcat。
但是我不是我的eclipse中的类的目录结构。
要得到正确的输出。
我想要当我运行j2me类(HitMIDlet)它击中servlet(HitServlet)并给出
put。
i am working with Eclipse to develop a application in J2ME.In This application i am using a servlet called HitServlet and a J2me Class HitMIDlet. I want to run this project using Eclipse.But i do not what is the directory structure and how i make directory structure. I am alredy configure J2ME plugin and Tomcat in my eclipse. But i do not what is the directory structure of my classes in my eclipse. To get the proper out put. I want when i run j2me class(HitMIDlet) it hit the servlet(HitServlet) and give the out put.
这是我的J2me类代码:
this is my J2me Class code:
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 = getAppProperty("HitMIDlet.URL");
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);
}
}
和servlet(HitServlet)
and the servlet (HitServlet)
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/plain");
response.setContentLength(message.length());
PrintWriter out = response.getWriter();
out.println(message);
}
}
推荐答案
让Eclipse生成目录结构。创建两个项目。一个用于J2ME as JavaME> MIDlet项目(假设您已正确安装移动工具插件)和其他JavaEE作为 Web>动态Web项目(假设您使用Eclipse进行Java EE和/或已安装 Web Tools 插件)。在移动客户端上运行J2ME项目,并在Tomcat服务器上运行JavaEE项目。
Just let Eclipse generate the directory structure. Create two projects. One for J2ME as JavaME> MIDlet project (assuming that you've correctly installed the Mobile Tools plugin) and other for JavaEE as Web > Dynamic Web Project (assuming that you're using Eclipse for Java EE and/or have installed Web Tools plugin separately). Run the J2ME project on the mobile client and run the JavaEE project on Tomcat server.
- Eclipse Mobile Tools documentation - Creating MIDlet project
- Eclipse Web Tools documentation - Creating Dynamic Web project
这篇关于servlet与J2me Project进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!