Javascript Android应用程序是否可以在不向用户显示web表单的情况下填写web表单?

Javascript Android应用程序是否可以在不向用户显示web表单的情况下填写web表单?,javascript,android,python,Javascript,Android,Python,这是一个用于学习目的的概念性想法。我不知道这是否可能。 我有一个Android活动,有一些文本字段和一个按钮。网上也有同样的表格。我需要的是; 当用户填写并按下android界面上的按钮时,它应该填写web表单并按下web表单上的按钮(可能使用JAVA脚本或其他什么,我不知道)。 我不需要代码,但只需要一个确切的想法如何做到这一点。:) 请检查一下这张图片,看看我在想什么。但我无法确定如何以及在何处应用JAVA脚本(如果需要) 谁能给我一个主意吗。 有趣的问题 我可以考虑两种选择: 您可以将an

这是一个用于学习目的的概念性想法。我不知道这是否可能。 我有一个Android活动,有一些文本字段和一个按钮。网上也有同样的表格。我需要的是; 当用户填写并按下android界面上的按钮时,它应该填写web表单并按下web表单上的按钮(可能使用JAVA脚本或其他什么,我不知道)。 我不需要代码,但只需要一个确切的想法如何做到这一点。:)

请检查一下这张图片,看看我在想什么。但我无法确定如何以及在何处应用JAVA脚本(如果需要)

谁能给我一个主意吗。 有趣的问题

我可以考虑两种选择:

  • 您可以将android表单发布到web表单在其目标属性中使用的服务

  • 如果您需要填写web表单并发布:

    • 2.1当您在android表单中按下OK按钮时,您可以在webView(可能以某种方式隐藏)中打开web表单,在url中设置包含android表单字段值的参数

    • 2.2在web表单中,使用javascript检查URL中是否有参数。如果存在参数,则填写表单并提交(也使用javascript)


  • 这是一种迂回的做法。相反,您应该让您的android表单像表单提交一样直接发出HTTP请求。

    这是一个简单的方法。无论您是使用php、asp还是jsp,都要为相同的页面编写代码,以插入数据并应用GET方法。然后构建用于选择数据的页面(在需要的地方),并将其编码为json表单。然后在android中尝试应用以下代码:(通过更改url和表单字段名称):

    包装ex.78;
    导入java.io.BufferedInputStream;
    导入java.io.BufferedReader;
    导入java.io.IOException;
    导入java.io.InputStream;
    导入java.io.InputStreamReader;
    导入java.io.UnsupportedEncodingException;
    导入java.util.ArrayList;
    导入org.apache.http.HttpResponse;
    导入org.apache.http.NameValuePair;
    导入org.apache.http.client.ClientProtocolException;
    导入org.apache.http.client.HttpClient;
    导入org.apache.http.client.entity.UrlEncodedFormEntity;
    导入org.apache.http.client.methods.HttpPost;
    导入org.apache.http.impl.client.DefaultHttpClient;
    导入org.apache.http.message.BasicNameValuePair;
    导入org.json.JSONException;
    导入org.json.JSONObject;
    导入android.app.Activity;
    导入android.database.CursorJoiner.Result;
    导入android.os.AsyncTask;
    导入android.os.Bundle;
    导入android.view.view;
    导入android.widget.EditText;
    导入android.widget.TextView;
    导入android.widget.Toast;
    公共类firstact扩展活动实现Z{
    /**在首次创建活动时调用*/
    编辑文本edt;
    文本视图电视;
    @凌驾
    创建时的公共void(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    edt=(EditText)findViewById(R.id.EditText01);
    tv=(TextView)findViewById(R.id.TextView01);
    setContentView(R.layout.main);
    }
    public void方法(视图v)抛出ClientProtocolException、IOException、JSONException
    {
    HttpClient hc=新的默认HttpClient();
    HttpPost hp=新的HttpPost(“http://www.akshaychatterjee.in/aks.php");
    ArrayList al=新的ArrayList();
    新增(新的BasicNameValuePair(“电话”,“3828929”);
    新增(新的BasicNameValuePair(“会话”、“dsfsd”);
    hp.setEntity(新的UrlEncodedFormEntity(al));
    HttpResponse hr=hc.execute(hp);
    InputStream in=hr.getEntity().getContent();
    BufferedReader br=新的BufferedReader(新的InputStreamReader(在“iso-8859-1”中),8);
    StringBuilder sb=新的StringBuilder();
    字符串ss;
    而((ss=br.readLine())!=null)
    {
    sb.追加(ss+“\n”);
    }
    }
    public void getdata(视图v)抛出ClientProtocolException、IOException、JSONException
    {
    HttpClient hc=新的默认HttpClient();
    HttpPost hp=新的HttpPost(“http://www.akshaychatterjee.in/aks1.php");
    ArrayList al=新的ArrayList();
    新增(新的BasicNameValuePair(“电话”,“34232”));
    hp.setEntity(新的UrlEncodedFormEntity(al));
    HttpResponse hr=hc.execute(hp);
    InputStream in=hr.getEntity().getContent();
    BufferedReader br=新的BufferedReader(新的InputStreamReader(在“iso-8859-1”中),8);
    StringBuilder sb=新的StringBuilder();
    字符串ss;
    而((ss=br.readLine())!=null)
    {
    sb.追加(ss+“\n”);
    }
    JSONObject jo=新的JSONObject(sb.toString());
    String pass=jo.getString(“会话”);
    Toast.makeText(this,pass,1.show();
    in.close();
    /*类db扩展异步任务
    {
    为某人做准备;
    串通;
    @凌驾
    受保护的字符串doInBackground(字符串…arg0){
    //TODO自动生成的方法存根
    HttpClient hc=新的默认HttpClient();
    HttpPost hp=新的HttpPost(“http://www.akshaychatterjee.in/aks1.php");
    ArrayList al=新的ArrayList();
    新增(新的BasicNameValuePair(“电话”,“34232”));
    试一试{
    hp.setEntity(新的UrlEncodedFormEntity(al));
    }捕获(不支持的编码异常e){
    //TODO自动生成的捕捉块
    e、 printStackTrace();
    }
    HttpResponse hr=null;
    试一试{
    hr=hc.execute(hp);
    }捕获(客户端协议例外e){
    //TODO自动生成的捕捉块
    e、 printStackTrace();
    }捕获(IOE异常){
    //TODO自动生成的捕捉块
    e、 printStackTrace();
    }
    InputStream in=null;
    试一试{
    in=hr.getEntity().getContent();
    }捕获(非法状态例外e1){
    //TODO自动生成的捕捉块
    e1.p
    
        package ex.even78;
    
       import java.io.BufferedInputStream;
        import java.io.BufferedReader;
        import java.io.IOException;
       import java.io.InputStream;
         import java.io.InputStreamReader;
       import java.io.UnsupportedEncodingException;
       import java.util.ArrayList;
    
     import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
     import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import android.app.Activity;
    import android.database.CursorJoiner.Result;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.view.View;
     import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class firstact extends Activity implements  Z{
    /** Called when the activity is first created. */
    EditText edt;
    TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        edt=(EditText)findViewById(R.id.EditText01);
        tv=(TextView)findViewById(R.id.TextView01);
        setContentView(R.layout.main);
    
    }
    public void method(View v) throws ClientProtocolException, IOException, JSONException
    {
        HttpClient hc=new DefaultHttpClient();
        HttpPost hp=new HttpPost("http://www.akshaychatterjee.in/aks.php");
        ArrayList<NameValuePair> al=new ArrayList<NameValuePair>();
        al.add(new BasicNameValuePair("phone", "3828929"));
        al.add(new BasicNameValuePair("session", "dsfsd"));
        hp.setEntity(new UrlEncodedFormEntity(al));
        HttpResponse hr=hc.execute(hp);
        InputStream in=hr.getEntity().getContent();
        BufferedReader br=new BufferedReader(new InputStreamReader(in,"iso-8859-1"),8);
        StringBuilder sb=new StringBuilder();
        String ss;
        while((ss=br.readLine())!=null)
        {
            sb.append(ss+"\n");
        }
    
    }
    public void getdata(View v) throws ClientProtocolException, IOException, JSONException 
    {
    
    
        HttpClient hc=new DefaultHttpClient();
        HttpPost hp=new HttpPost("http://www.akshaychatterjee.in/aks1.php");
        ArrayList<NameValuePair> al=new ArrayList<NameValuePair>();
        al.add(new BasicNameValuePair("phone","34232"));
        hp.setEntity(new UrlEncodedFormEntity(al));
        HttpResponse hr=hc.execute(hp);
        InputStream in=hr.getEntity().getContent();
        BufferedReader br=new BufferedReader(new InputStreamReader(in,"iso-8859-1"),8);
        StringBuilder sb=new StringBuilder();
        String ss;
        while((ss=br.readLine())!=null)
        {
            sb.append(ss+"\n");
        }
    
        JSONObject jo=new JSONObject(sb.toString());
        String pass=jo.getString("session");
        Toast.makeText(this, pass, 1).show();
    
        in.close();
        /*class db extends AsyncTask<String, Void, String>
        {
    
            StringBuilder sb;
    
        String pass;
            @Override
            protected String doInBackground(String... arg0) {
                // TODO Auto-generated method stub
                HttpClient hc=new DefaultHttpClient();
                HttpPost hp=new HttpPost("http://www.akshaychatterjee.in/aks1.php");
                ArrayList<NameValuePair> al=new ArrayList<NameValuePair>();
                al.add(new BasicNameValuePair("phone","34232"));
                try {
                    hp.setEntity(new UrlEncodedFormEntity(al));
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                HttpResponse hr = null;
                try {
                    hr = hc.execute(hp);
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                InputStream in = null;
                try {
                    in = hr.getEntity().getContent();
                } catch (IllegalStateException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                BufferedReader br = null;
                try {
                    br = new BufferedReader(new InputStreamReader(in,"iso-8859-1"),8);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                 sb=new StringBuilder();
                String ss;
                try {
                    while((ss=br.readLine())!=null)
                    {
                        sb.append(ss+"\n");
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                try {
                    in.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    
                return pass;
            }
               protected void onPostExecute(String...  arg0)  {
    
                   tv.setText(pass);
            }
    
    
        }*/
        //db d=new db();
        //d.execute();
    }