Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler.
O que preciso adaptar nesse código para enviar corretamente, na Servlet estou recebendo via service.
Na Servlet so imprimo o valor:
if(acao.equals("jme")){
System.out.println("chegou do celular");
System.out.println("renda " + request.getParameter("renda"));
}
java.lang.SecurityException: Application not authorized to access the restricted API
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(+40)
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(+7)
at com.sun.midp.midletsuite.MIDletSuiteImpl.checkIfPermissionAllowed(+8)
at com.sun.midp.midlet.MIDletState.<init>(+78)
at javax.microedition.midlet.MIDletProxy.<init>(+5)
at javax.microedition.midlet.MIDlet.<init>(+13)
at PesquisaEleitoral.<init>(+4)
at PesquisaEleitoral.commandAction(+7)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
Consegui estava dando um new na classe e gerava a Exception, porem agora estou com problemas para gravar datas.
Quando tento passar gera o seguinte erro:
Uncaught exception java/lang/IllegalArgumentException: Space character in URL.
Separei em 2 classes agora
public class EnviaServlet extends Thread {
private String renda;
private int candidato;
private Date dataNascimento;
public EnviaServlet(PesquisaEleitoral pesquisa){
this.renda = pesquisa.renda.getString();
this.candidato = pesquisa.voto.getSelectedIndex();
this.dataNascimento = pesquisa.nascimento.getDate();
}
public void sendServlet() throws IOException{
String url = "http://localhost:8080/myapplication/controller?acao=jme"+"&renda="+renda+"&candidato="+candidato+"&nascimento="+dataNascimento;
HttpConnection http = (HttpConnection) Connector.open(url);
http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
http.setRequestMethod(HttpConnection.GET);
OutputStream oStrm = http.openOutputStream();
String data = "&renda="+renda.getBytes();
oStrm.write(data.getBytes());
oStrm.flush();
}
public void run(){
try {
sendServlet();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Uma outra coisa que notei se eu não passar algum byte com write e flush não chega nada na Servlet por que?