モデル名を送信し、String
それをサーブレット Web ページのコンボ ボックスに追加する Java サーブレットに送信する Android アプリがあります。これは現在発生していません。次の例外が Logcat に表示されます
10-28 14:25:05.733: D/Exception(7518): java.io.FileNotFoundException: MyServletProject/Connection_Servlet
これは私のアプリコードです
public void onClick(View v) {
switch (v.getId()){
case R.id.doubleme:
new Thread(new Runnable() {
public void run() {
try{
URL url = new URL("http://192.168.1.5:8080/MyServletProject/Connection_Servlet");
//URL url = new URL("http://10.0.2.2:8080/MyServletProject/DoubleMeServlet");
URLConnection connection = url.openConnection();
String inputString = "11";
String model=getDeviceName();
//inputString = URLEncoder.encode(inputString, "UTF-8");
Log.d("inputString", inputString);
Log.d("inputString",model);
connection.setDoOutput(true);
/* OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(inputString);
out.close();*/
DataOutputStream out1 = new DataOutputStream(connection.getOutputStream());
out1.writeUTF(model);
out1.writeUTF(inputString);
out1.flush();
out1.close();
InputStream is =connection.getInputStream();
DataInputStream dis =new DataInputStream(is);
while(dis.available()==0);
String WTF = dis.readUTF();
dis.close();
Log.d("Message",WTF);
}catch(Exception e)
{
Log.d("Exception",e.toString());
}
}
これは私のサーブレットコードです
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setIntHeader("Refresh", 5);
request.setAttribute("item",list);
request.getServletContext().getRequestDispatcher("/BarcodeScannerTest.jsp").forward(request, response);
}
boolean dataon = false;
boolean Device_connected =false;
public String model;
ArrayList<String> list = new ArrayList<String>( Arrays.asList("Buenos Aires", "Córdoba", "La Plata"));
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
InputStream is =request.getInputStream();
DataInputStream dis =new DataInputStream(is);
while(dis.available()==0);
model = dis.readUTF();
String input = dis.readUTF();
dis.close();
System.out.println("Model:"+model);
list.add(model);
OutputStream dout=response.getOutputStream();
DataOutputStream dat = new DataOutputStream(dout);
dat.writeUTF("Working");
dat.flush();
dat.close();
doGet(request,response);
}
}