JSP页面中的绑定值

时间:2018-02-01 14:14:34

标签: java jsp spring-mvc

我在控制器中有一个XML值,我将该值传递给jsp页面和绑定,如下面的代码所示。

 <input type="hidden" id="thisField" name="inputName" value='${xml}'/>

它绑定了值,如下所示。

 <input type="hidden" id="thisField" name="inputName" value='
    <?xml version="1.0" encoding="UTF-8"?>
    <Esign AuthMode="1" aspId="ASPRBLBMUMTEST043" ekycId="448988431774" ekycIdType="A" ekycMode="U" organizationFlag="N" preVerified="n" responseSigType="pkcs7" responseUrl="http://10.80.49.41" sc="Y" ts="2018-01-19T11:42:55" txn="UKC:eSign:6539:20180119114250963" ver="2.0">
        <Docs>
            <InputHash docInfo="Signing pdf" hashAlgorithm="SHA256" id="1">30e3ed7f512da50206b8720d52457309c87f4edfee85d08f937aef3f955fb7af</InputHash>
        </Docs>
        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SignedInfo>
                <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
                <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
                <Reference URI="">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                    <DigestValue>kQEB9r4dd5hhdaPxc4sjPMG3SGM=</DigestValue>
                </Reference>
            </SignedInfo>
            <SignatureValue>MSgEXK2+GpwnRBr3vLNncqc9FOY0oDhjlhfyihOjrUPFZAL8eBms6jXdhoWGlrypaF6hE70ZltDQbQTArrk/mfCmoVvna7yEJN9gDh6gAHbh9Zj4BEBdWhd85DKbAdtSy8zYTKIeIjhFBzOItUAhSN7lFrEFVrTLV5wO38hswD7LlaY4ZBSNMWbpHPx+Io6ukdP8b4n95dqoB9iiqKxg3nK0RslhLRcPoe4B2AsdoiZ42iY/tZ4disOzyOCyCdE8nRxipJbP9HZS3psCSCar3CPSigXiNk6fY7+bDEFbJrfoqhHBk1hasx2m0TbxZVeOIPSUPRYpekHCm0sm4RvZhA==</SignatureValue>
            <KeyInfo>
                <X509Data>
                    <X509SubjectName>CN=AAA Bank Test,OU=AAA Bank IT Dept,O=AAA Bank,L=Delhi,ST=Delhi,C=91</X509SubjectName>
                    <X509Certificate>MIIDkTCCAnmgAwIBAgIEZNl4CjANBgkqhkiG9w0BAQsFADB5MQswCQYDVQQGEwI5MTETMBEGA1UECBMKTWFoYXJhc3RyYTEPMA0GA1UEBxMGTXVtYmFpMREwDwYDVQQKEwhSYmwgQmFuazEZMBcGA1UECxMQUkJMIEJhbmsgSVQgRGVwdDEWMBQGA1UEAxMNUmJsIEJhbmsgVGVzdDAeFw0xNzAzMDIxNDA4MTBaFw0xODAyMjUxNDA4MTBaMHkxCzAJBgNVBAYTAjkxMRMwEQYDVQQIEwpNYWhhcmFzdHJhMQ8wDQYDVQQHEwZNdW1iYWkxETAPBgNVBAoTCFJibCBCYW5rMRkwFwYDVQQLExBSQkwgQmFuayBJVCBEZXB0MRYwFAYDVQQDEw1SYmwgQmFuayBUZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsjsF71lv96Y+2DbuSgk1U/Bp3P+jPpKp9GpwiVuIAf4SsBc1bqR3x4JSnY4COdUlq2IkHYSGnufGkPS6tH4edoFpZrSBAiTo1D0WQQ4KoRWBzn9xptMGsJBoV7dcSovjjD1HhUJGNnfoxjBh3AmIe8ZySWhuouEA8cRtFcHoWunpSB1FOJreIZ1P/ZnJ7C4gu+E1ccXjkFPqCGI9RcdUSE72K+ovtI/yWIUPwXdj3O/k30iX2owxUVFKnCmIDFnKDJ/b96RDzlIB9FiH5IVQm4mcU6HiQKqknDI3bPKlwvfFfB+YI69vjRQf3dvsca2nZQsYT3iSgkxBwoiugsD59QIDAQABoyEwHzAdBgNVHQ4EFgQUwFYILDVGVtIJgYveFqZ9YRrRq4AwDQYJKoZIhvcNAQELBQADggEBAKygyzVE1sOaBxuj4IjGDmo2y5UOhPOzklRocZbsqycEApcBn5m/dVauvewqw7An1vrkvjTYbTUCjUKghNW/MdtiWbKKRDy3fA8DyEACcYuK0PpaaXMTJFjIjKxXko6Rmmp6CKFcmERgetiwrFreMfFjvCv9H1fk7FSR87d/17l/LsmAndFIvpZTF3Ruz4lZsoL2qWtBF+wnVjFW+yqf6nXDqE/Swxhiq7dZ+Dl0ilgEsh3Q1WOO/S/TBDkeURIHfIkc886p5M4u5iQdkO1fndptUhBNbaM1idMOW/5QUWFeIEChdSo3mrVVTWyvhQEkYls0GYJUSVSdaITcyE3xkJA=</X509Certificate>
                </X509Data>
            </KeyInfo>
        </Signature>
    </Esign>'/>

但我想在没有空格的情况下如下所示进行绑定。

<input type="hidden" id="thisField" name="inputName" value='<?xml version="1.0" encoding="UTF-8"?><Esign AuthMode="1" aspId="ASPRBLBMUMTEST043" ekycId="448988431774" ekycIdType="A" ekycMode="U" organizationFlag="N" preVerified="n" responseSigType="pkcs7" responseUrl="http://10.80.49.41" sc="Y" ts="2018-01-19T11:42:55" txn="UKC:eSign:6539:20180119114250963" ver="2.0"><Docs><InputHash docInfo="Signing pdf" hashAlgorithm="SHA256" id="1">30e3ed7f512da50206b8720d52457309c87f4edfee85d08f937aef3f955fb7af</InputHash></Docs><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>kQEB9r4dd5hhdaPxc4sjPMG3SGM=</DigestValue></Reference></SignedInfo><SignatureValue>MSgEXK2+GpwnRBr3vLNncqc9FOY0oDhjlhfyihOjrUPFZAL8eBms6jXdhoWGlrypaF6hE70ZltDQbQTArrk/mfCmoV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UVFKnCmIDFnKDJ/b96RDzlIB9FiH5IVQm4mcU6HiQKqknDI3bPKlwvfFfB+YI69vjRQf3dvsca2nZQsYT3iSgkxBwoiugsD59QIDAQABoyEwHzAdBgNVHQ4EFgQUwFYILDVGVtIJgYveFqZ9YRrRq4AwDQYJKoZIhvcNAQELBQADggEBAKygyzVE1sOaBxuj4IjGDmo2y5UOhPOzklRocZbsqycEApcBn5m/dVauvewqw7An1vrkvjTYbTUCjUKghNW/MdtiWbKKRDy3fA8DyEACcYuK0PpaaXMTJFjIjKxXko6Rmmp6CKFcmERgetiwrFreMfFjvCv9H1fk7FSR87d/17l/LsmAndFIvpZTF3Ruz4lZsoL2qWtBF+wnVjFW+yqf6nXDqE/Swxhiq7dZ+Dl0ilgEsh3Q1WOO/S/TBDkeURIHfIkc886p5M4u5iQdkO1fndptUhBNbaM1idMOW/5QUWFeIEChdSo3mrVVTWyvhQEkYls0GYJUSVSdaITcyE3xkJA=</X509Certificate></X509Data></KeyInfo></Signature></Esign>'/>
  

有没有办法绑定,如上所示?

1 个答案:

答案 0 :(得分:0)

您可以使用一点regex对控制器中的xml字符串进行操作,以消除换行符和空格。

这是一个小java应用程序,用于显示正在使用xml字符串的正则表达式。

import { some, isEmpty } from 'lodash'
console.log(some(this.yourObject, isEmpty))

控制器中只需要正则表达式。

public class StripXmlWhitespace {

       public static void main (String [] args) {
           String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 
                "    <Esign AuthMode=\"1\" aspId=\"ASPRBLBMUMTEST043\" ekycId=\"448988431774\" ekycIdType=\"A\" ekycMode=\"U\" organizationFlag=\"N\" preVerified=\"n\" responseSigType=\"pkcs7\" responseUrl=\"http://10.80.49.41\" sc=\"Y\" ts=\"2018-01-19T11:42:55\" txn=\"UKC:eSign:6539:20180119114250963\" ver=\"2.0\">\n" + 
                "        <Docs>\n" + 
                "            <InputHash docInfo=\"Signing pdf\" hashAlgorithm=\"SHA256\" id=\"1\">30e3ed7f512da50206b8720d52457309c87f4edfee85d08f937aef3f955fb7af</InputHash>\n" + 
                "        </Docs>\n" + 
                "        <Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n" + 
                "            <SignedInfo>\n" + 
                "                <CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>\n" + 
                "                <SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>\n" + 
                "                <Reference URI=\"\">\n" + 
                "                    <Transforms>\n" + 
                "                        <Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>\n" + 
                "                    </Transforms>\n" + 
                "                    <DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>\n" + 
                "                    <DigestValue>kQEB9r4dd5hhdaPxc4sjPMG3SGM=</DigestValue>\n" + 
                "                </Reference>\n" + 
                "            </SignedInfo>\n" + 
                "            <SignatureValue>MSgEXK2+GpwnRBr3vLNncqc9FOY0oDhjlhfyihOjrUPFZAL8eBms6jXdhoWGlrypaF6hE70ZltDQbQTArrk/mfCmoVvna7yEJN9gDh6gAHbh9Zj4BEBdWhd85DKbAdtSy8zYTKIeIjhFBzOItUAhSN7lFrEFVrTLV5wO38hswD7LlaY4ZBSNMWbpHPx+Io6ukdP8b4n95dqoB9iiqKxg3nK0RslhLRcPoe4B2AsdoiZ42iY/tZ4disOzyOCyCdE8nRxipJbP9HZS3psCSCar3CPSigXiNk6fY7+bDEFbJrfoqhHBk1hasx2m0TbxZVeOIPSUPRYpekHCm0sm4RvZhA==</SignatureValue>\n" + 
                "            <KeyInfo>\n" + 
                "                <X509Data>\n" + 
                "                    <X509SubjectName>CN=AAA Bank Test,OU=AAA Bank IT Dept,O=AAA Bank,L=Delhi,ST=Delhi,C=91</X509SubjectName>\n" + 
                "                    <X509Certificate>MIIDkTCCAnmgAwIBAgIEZNl4CjANBgkqhkiG9w0BAQsFADB5MQswCQYDVQQGEwI5MTETMBEGA1UECBMKTWFoYXJh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dkO1fndptUhBNbaM1idMOW/5QUWFeIEChdSo3mrVVTWyvhQEkYls0GYJUSVSdaITcyE3xkJA=</X509Certificate>\n" + 
                "                </X509Data>\n" + 
                "            </KeyInfo>\n" + 
                "        </Signature>\n" + 
                "    </Esign>";
           String output = xmlString.replaceAll(">\\s+<", "><");
           System.out.println(xmlString);
           System.out.println(output);

       }

}

在发送之前基本上取消格式化xml将其绑定到视图。我希望有所帮助。