1

我的jsp文件中有这个:

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

它有效,当我通过android提交它时我得到了“名称”,但随后它恢复为null。我如何让它保持“名字”?

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

进一步澄清:当我在服务器控制台中打印“request.getParameter”给我的内容时,我得到了通过我的 Android 应用程序上的提交按钮发送的值,然后是两个空值。

所以我得到:

实际价值

无效的

无效的

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

工作流程:

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

然后我的 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);
4

1 回答 1

0

尝试使用适当的引号:

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

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

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

编辑

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

HttpResponse response = httpclient.execute(httppost);

因为,这是您设置名称-值对的请求,所以这将设置 JavaScript 变量。

于 2013-07-30T18:48:34.120 回答