搞j2me开发的兄弟帮忙啊!我的程序怎么连接不了jsp啊!在线等待!马上给分!
2017-01-03 00:55
337 查看
搞j2me开发的兄弟帮忙啊!我的程序怎么连接不了jsp啊!jsp没有问题!
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
public class InvokeJSPMidlet extends MIDlet implements CommandListener {
Display display=null;
TextField name=null;
Form form;
String url="http://192.168.0.213/hello.jsp";
static final Command callCommand=new Command("data",Command.OK,2);
static final Command clearCommand=new Command("clear",Command.STOP,2);
String myname;
public InvokeJSPMidlet() {
display=Display.getDisplay(this);
name=new TextField("Name;","",25,TextField.ANY);
form=new Form("Invoke JSP");
}
public void startApp()throws MIDletStateChangeException {
form.append(name);
form.addCommand(clearCommand);
form.addCommand(callCommand);
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
void invokeJSP(String url)throws IOException {
HttpConnection c=null;
InputStream is=null;
OutputStream os=null;
StringBuffer b=new StringBuffer();
TextBox t=null;
try {
String ua="Profile/"+System.getProperty("microedition.profiles")+"Configuration/"+System.getProperty("microedition.configuration");
c=(HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("IF-Modified-Since", "29 Dec 2001 15:17:19 GMT");
c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-CA");
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
os=c.openOutputStream();
os.write(("name="+myname).getBytes());
os.flush();
is=c.openDataInputStream();
int ch;
while((ch=is.read())!=-1)
{b.append((char)ch);
System.out.print((char)ch);
}
t=new TextBox("Date",b.toString(),1024,0);
t.setCommandListener(this);
} finally {
if(is!=null)
{is.close();}
if(os!=null)
{os.close();}
if(c!=null)
{c.close();}}
display.setCurrent(t);
}
public void commandAction(Command c,Displayable d) {
String label=c.getLabel();
if(label.equals("clear")){
destroyApp(true);
}else if(label.equals("data"))
{ myname=name.getString();
try {
invokeJSP(url);}catch(IOException e) {}
}}}
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
public class InvokeJSPMidlet extends MIDlet implements CommandListener {
Display display=null;
TextField name=null;
Form form;
String url="http://192.168.0.213/hello.jsp";
static final Command callCommand=new Command("data",Command.OK,2);
static final Command clearCommand=new Command("clear",Command.STOP,2);
String myname;
public InvokeJSPMidlet() {
display=Display.getDisplay(this);
name=new TextField("Name;","",25,TextField.ANY);
form=new Form("Invoke JSP");
}
public void startApp()throws MIDletStateChangeException {
form.append(name);
form.addCommand(clearCommand);
form.addCommand(callCommand);
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
void invokeJSP(String url)throws IOException {
HttpConnection c=null;
InputStream is=null;
OutputStream os=null;
StringBuffer b=new StringBuffer();
TextBox t=null;
try {
String ua="Profile/"+System.getProperty("microedition.profiles")+"Configuration/"+System.getProperty("microedition.configuration");
c=(HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("IF-Modified-Since", "29 Dec 2001 15:17:19 GMT");
c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-CA");
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
os=c.openOutputStream();
os.write(("name="+myname).getBytes());
os.flush();
is=c.openDataInputStream();
int ch;
while((ch=is.read())!=-1)
{b.append((char)ch);
System.out.print((char)ch);
}
t=new TextBox("Date",b.toString(),1024,0);
t.setCommandListener(this);
} finally {
if(is!=null)
{is.close();}
if(os!=null)
{os.close();}
if(c!=null)
{c.close();}}
display.setCurrent(t);
}
public void commandAction(Command c,Displayable d) {
String label=c.getLabel();
if(label.equals("clear")){
destroyApp(true);
}else if(label.equals("data"))
{ myname=name.getString();
try {
invokeJSP(url);}catch(IOException e) {}
}}}
相关文章推荐
- 帮忙推荐一下j2me程序真机测试手机,在线等.....
- J2ME的程序,用到SOCKET,要想在Windows Mobile上跑,要怎么写socket的连接?
- 用Idea编写JSP程序进行Javaweb开发时,网页出现乱码怎么办?
- J2ME 发送彩信问题,请个位高手帮忙,长时间在线等待
- JSP开发WEB程序时注意的问题(中文化,数据库连接,目录)
- 用vb制作ActiveX Dll中,怎么让程序连接远程机器1888端口,并且等待接收信息
- J2ME技术入门之一——J2ME程序的开发过程
- 使用 Jbulider 开发 J2ME 移动游戏程序
- J2ME程序开发新手入门九大要点 2005.11.22
- 用sun公司的NetBeans开发J2ME程序
- 在J2ME手机程序开发中使用颜色
- 关于把C程序连接到核心的设置, --核心开发入门
- 使用EclipseME开发J2ME程序
- 用j2me开发GIS程序-读入数据2
- 教您如何使用EclipseME开发J2ME程序
- 在J2ME中使用MMAPI开发摄像头程序
- 关于Eclipse3.0+EclipseME0.6.1+j2sdk1.42开发J2me程序的环境配置!
- 使用EclipseME开发J2ME程序
- [转]教您如何使用EclipseME开发J2ME程序(2)
- 用j2me开发GIS程序-地图绘制1