Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法获取服务器中的参数_Java_Jsp_Tomcat - Fatal编程技术网

Java 无法获取服务器中的参数

Java 无法获取服务器中的参数,java,jsp,tomcat,Java,Jsp,Tomcat,当我试图从请求中获取参数时遇到了一个问题,我只得到了NULL。 JSP文件如下所示: <%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"

当我试图从请求中获取参数时遇到了一个问题,我只得到了NULL。 JSP文件如下所示:

    <%@ page contentType="text/html; charset=UTF-8" %>

<%@ taglib uri="http://struts.apache.org/tags-html"  prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean"  prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html:html locale="true">
    <head>
        <META HTTP-EQUIV="pragma" CONTENT="no-cache">
        <META HTTP-EQUIV="cache-control" CONTENT="no-cache">
        <META HTTP-EQUIV="expires" CONTENT="0">
        <META HTTP-EQUIV="Content-Type" content="text/html; charset=UTF-8">
        <META HTTP-EQUIV="Content-Script-Type" content="text/javascript">
        <META HTTP-EQUIV="Content-Style-Type"  content="text/css">
        <link rel="stylesheet" type="text/css" href="css/base.css">

        <title>Menu</title>
<SCRIPT language="JavaScript">
<!--
    function nextPage(url) {
        location.replace(url);
    }
    function setUrl(url) {
        document.forms[0].url.value = url;
    }
//-->
</SCRIPT>

    </head>
    <body tabindex="-1">
        <%-- ページ・ボディ --%>
        <html:form action="/select.do?apl500_p=1" method="post" target="_self" >
            <html:hidden property="url" value ="" />

            <table style="width:100%;" border="0">
                <tr>
                    <td style="width:100%;text-align:center">
                        <font size="5" color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <B>Menu</B></font>
                    </td>
                    <td style="text-align:right">
                        <html:submit property="submit_logout" value="Logout" tabindex="-1"/>
                    </td>
                </tr>
            </table>

            <hr><br>

            <div align="center" style="width:90%;height:482px;overflow:auto;margin-left:40px;">
            <table  border="0">
                <tr>
                    <td style="width:100%;text-align:center">
<html:submit property="btn1" value="アプリケーション1" onclick="setUrl('/aplXXX')" style="width:400px;height=150px;font-size:14pt;"/>
                    </td>
                </tr>
                <tr>
                    <td style="width:100%;text-align:center">
<html:submit property="btn2" value="新共通認証システム(ローカル環境用)テスト" onclick="setUrl('/authTest')" style="width:400px;height=150px;font-size:14pt;"/>
                    </td>
                </tr>
            </table>

            </div>

            <%-- ページ・フッダー --%>
            <%@ include file="/WEB-INF/jsp/footer.inc" %>

        </html:form>
    </body>
</html:html>
<% out.flush(); %>

菜单
菜单


当我使用“request.getParameterNames()”时,我只能获取“apl500_p”参数,而无法获取“url”参数。我用的是tomcat7.0.41,但如果我用的是tomcat5.5.36,就没问题了。 我不知道为什么。tomcat7.0.41有什么问题吗?
我使用了Fiddler2,我确信“url”参数已发送到服务器。

尝试删除表单action值中的apl500\u p=1

 action="/select.do"
这样,它将把所有表单元素传递给servlet。向表单操作添加参数可防止出现这种情况。如果您需要apl500_p值,我建议您创建另一个隐藏字段,如:

 <html:hidden property="apl500_p" value ="1" />

根据您的讨论,我怀疑参数
url
为空,因为浏览器使用的字符编码与服务器使用的字符编码不同

在浏览器向服务器发送参数之前,它会对参数进行URL编码。此编码方法使用百分比编码对某些字符(例如,日语字符)进行编码。百分比编码方法首先根据指定的字符集将字符转换为字节。然后,它将这些字节编码为十六进制数字序列,前缀为“%”字符。这个字符集就是我所说的浏览器使用的字符编码

然后,服务器将检索到的参数解码回其原始形式。它首先将十六进制数字序列解码为一个字节序列。然后,它根据指定的字符集将每个字节转换为一个字符。这里的问题是服务器需要使用与浏览器使用的字符集相同的字符集。通常情况下,请求不包含有关浏览器使用的字符集的信息,导致服务器尽最大努力猜测。如果猜测不正确,则解码过程会无声地失败,并返回NULL,这就是您的情况

不同的web服务器有不同的猜测方式。Web服务器可以查看内容类型头、内容语言头、接受头、接受语言头、配置文件等

由于我对两个Tomcat版本都不熟悉,所以我无法准确地指出如何解决这个问题。但是,您可以从研究Tomcat如何计算字符编码开始。在WebSphereApplicationServer中,有一个配置文件,可以修改该文件以指定服务器使用的默认字符编码


参数
apl500\u p
不为空,因为
1
的URL编码形式也是
1
。服务器解码回来没有任何问题。

我尝试过,但仍然无法工作。我可以从ServletInputStream获取url:stream:url=%2FALPXXX&apl500_p=1&btn1=%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%EF%BC%91。但我无法从参数或属性中获取url。当您使用btn1和btn2提交表单时是否调用setUrl(url)?您如何在请求页面请求参数?很抱歉,我不知道您的确切意思?我在action类中请求参数。我指的是在action hope u r使用request.GetParameter?我发现了问题,日本人,如果我改变日本人”アプリケーション1" 在英语中,它会起作用。可能问题在于编码。哦……对于这种用法,请使用
请求。setCharacterEncoding(“UTF-8”);
在ur
doget
dopost
方法的strt处