I'我在jsp服务器上收到了一个来自android应用程序的HTTPPOST,我该如何将数据传递到Javascr

I've received an HTTP POST from an android app in my jsp server, how do I pass that data into a Javascript function

本文关键字:HTTPPOST android 应用程序 Javascr 数据 一个 jsp 服务器 我在      更新时间:2023-09-26

我的jsp文件中有这个:

<form name='form1'>
<input type='hidden' name=NAME value=<%=request.getParameter("name")%> />
</form>

它是有效的,当我通过android提交它时,我得到了"名称",但随后它又恢复为null。我怎样才能让它保持"name"?

此外,我将request.getParameter放入一个表单中,以便能够使用"document.form1.NAME.value"访问js代码中的值

进一步澄清:当我在服务器控制台中打印"request.getParameter"给我的信息时,我会通过Android应用程序上的提交按钮获得我要发送的值,然后是两个null。

所以我得到:

实际值

jsp好像运行了三次??并将request.getParameter设置回null?

工作流程:

我有一个android应用程序,当你点击提交按钮时,它会将用户输入的任何字符串(在应用程序的文本框中)发送到一个Tomcat服务器,该服务器上有一个jsp文件

然后,我的jsp文件读取请求。

我的javascript需要字符串(它获取字符串,对其进行修改,然后用修改后的字符串显示警报)。

可能是因为我在发送请求后打开了jsp文件,所以它找不到以前的请求吗

HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("Tomcat server with my.jsp");
        EditText nameBox = (EditText)findViewById(R.id.name);
        String n = nameBox.getText().toString();
        try
        {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("name", n));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
        }
        catch (ClientProtocolException e)
        {
        }
        catch (IOException e)
        {
        }
        String url = "The same server and same.jsp file";
        Intent webIntent = new Intent(Intent.ACTION_VIEW);
        webIntent.setData(Uri.parse(url));
        startActivity(webIntent);

尝试使用正确的引号:

<form name='form1'>
  <input type='hidden' name='NAME' value='<%= request.getParameter("name") %>' />
</form>

尝试将脚本变量直接设置为

var name = '<%= request.getParameter ("name") %>';

编辑

是的,您正在发出两个不同的HTTP请求。webIntent.setData(Uri.parse(url));将提出一个新的请求,但不会提交name-post参数。你需要的是以某种方式在你的应用程序中呈现之前收集的响应。

HttpResponse response = httpclient.execute(httppost);

由于这是设置名称-值对的请求,因此会设置JavaScript变量。