繁体   English   中英

将表单数据从jsp发送到Web服务客户端(SOAP)

[英]Sending form data from a jsp to a web service client (SOAP)

基本上,我有一个连接到数据库的Web服务,该服务具有insert方法。 我已经在jsp中创建了一个注册表单,并且需要将用户在registration.jsp表单中插入的数据发送到我的Web服务。 因此,当单击“提交”按钮时,我将Web服务客户端调用用作对registration.jsp的操作。

我不知道如何获取用户在表单中输入的数据并将其传递给Web客户端,Web客户端又将其插入我的Web服务数据库中。

这是我的代码:

    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title> Registration</title>
    </head>
    <body>
        <h1> Welcome</h1>


        <form name="test" action="Wclient2.jsp" method="POST" enctype="multipart/formdata">

                   <table border="0">
                <thead>
                    <tr>
                        <th>Register Here</th>
                      <th></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>First Name:</td>
                        <td><input type="text" name="fname" value="" size="50" /></td>
                    </tr>
                    <tr>
                        <td>Last Name:</td>
                        <td><input type="text" name="lname" value="" size="50" /></td>
                    </tr>
                    <tr>
                        <td>Email:</td>
                        <td><input type="text" name="email" value="" size="50" /></td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td><input type="password" name="password" value="" size="50"/>      </td>
                    </tr>

                    <tr>
                        <td></td>
                        <td> <input type="submit" value="submit" name="submit" /> </td>
                    </tr>
                </tbody>
            </table>

        </form>
    </body>
</html>

这是Web客户端上单击“提交”按钮的代码。

注册(action =“ Wclient2.jsp” method =“ POST”)

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title> Enroll</title>
    </head>
    <body>
        <h1> Welcome</h1>

        <form name="test"<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>

           <%-- start web service invocation --%><hr/>
        <%        

            try {
                mypack.Bioweb_Service service = new mypack.Bioweb_Service();
                mypack.Bioweb port = service.getBiowebPort();
                // TODO initialize WS operation arguments here

                java.lang.String fname = "";
                java.lang.String lname = "";
                java.lang.String email = "";
                java.lang.String password = "";

                // TODO process result here

                java.lang.String result = port.insert(fname, lname, email, password);
                out.println("Result = " + result);

            } catch (Exception ex) {
                // TODO handle custom exceptions here
            }
        %>
        <%-- end web service invocation --%><hr/>

    </body>
</html>

我不知道如何从registration.jsp获取fname的参数以放入Web客户端。 当我写:

java.lang.String fname = request.getParameter(“ fname”);

为了将文本字段fname的值输入到我的Web服务中,在数据库中创建了一行,但是插入了NULL,而不是用户在表单中输入的值。

请帮忙。

如果您使用request.getParameter(“ fname”),只要您向FirstName提供输入,我的客户端代码(html / jsp)就不会出现任何问题。 为了找出问题所在,请在您的jsp中打印fname的值

String fname =request.getParameter("fname") ;
System.out.println("Value of first name " +fname) // this will print your console
java.lang.String result = port.insert(fname, lname, email, password);

如果这样可以正确打印您的输入,则需要查看服务实现以检查它的读取并正确处理输入。 如果fname为null,那么我们可以回到HTML / JSP进行第二次查看。

更新:要查看请求的详细信息,可以使用以下代码

Enumeration reqParams= request.getParameterNames();
while (reqParams.hasMoreElements()) {
    String key= (String) reqParams.nextElement();
    String val = request.getParameter(element);
    System.out.println(" Key ==> "+key+" , Value ==> "+val);

}

试试这个,让我们看看您是否获得了在html表单中输入的任何输入的值。

萨特什

这实际上不是我的专业领域,但是您可以调用action =“ pass.php”而不是调用action =“ Wclient2.jsp”,然后创建一个php文件来获取变量并重定向到Wclient2.jsp,并在其中传递变量查询字符串。

例如在pass.php文件中:

$fname = $_POST['fname'];
$lname = $_POST['lname'];

header( 'Location: http://www.yoursite.com/path/Wclient2.jsp?fname=' .fname. '&lname=' .lname );

那可能是一种很奇怪(或新手)的实现方式,但是我的头顶上我确实知道它有效。 希望其他人会有一个更合适的答案,但是如果没有人足够迅速地答复,我希望这会有所帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM