Java 将表单数据从jsp发送到web服务客户端(SOAP)
基本上,我有一个连接到数据库的web服务,它有一个insert方法。 我已经在jsp中创建了一个注册表单,需要将用户在registration.jsp表单中插入的数据发送到我的web服务。因此,在单击submit按钮时,我使用web服务客户端调用作为registration.jsp的操作 我不知道如何获取用户在表单中输入的数据并将其传递给web客户机,然后由web客户机将其插入到我的web服务数据库中 这是我的密码:Java 将表单数据从jsp发送到web服务客户端(SOAP),java,jsp,soap,netbeans-7,webservice-client,Java,Jsp,Soap,Netbeans 7,Webservice Client,基本上,我有一个连接到数据库的web服务,它有一个insert方法。 我已经在jsp中创建了一个注册表单,需要将用户在registration.jsp表单中插入的数据发送到我的web服务。因此,在单击submit按钮时,我使用web服务客户端调用作为registration.jsp的操作 我不知道如何获取用户在表单中输入的数据并将其传递给web客户机,然后由web客户机将其插入到我的web服务数据库中 这是我的密码: <html> <head>
<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>
登记处
欢迎
在这里注册
名字:
姓氏:
电邮:
密码:
这是单击
注册(action=“Wclient2.jsp”method=“POST”)
登记
欢迎
这并不是我的专业领域,但是可以调用action=“Wclient2.jsp”而不是action=“pass.php”,然后创建一个php文件来获取变量,并重定向到Wclient2.jsp,在查询字符串中传递变量
例如,在pass.php文件中:
$fname = $_POST['fname'];
$lname = $_POST['lname'];
header( 'Location: http://www.yoursite.com/path/Wclient2.jsp?fname=' .fname. '&lname=' .lname );
这可能是一个非常奇怪(或新手)的方式来完成它,但就在我的头顶上,我确实知道它的工作。
希望其他人会有一个更合适的答案,但如果没有人足够快地回复,我希望这有一点帮助:)如果您使用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表单中输入的任何值
你好,谢谢你的回复。我试过你说的,但是,它仍然给我空,我不明白为什么!输出:名字的值为空。你能帮我吗。编辑了我以前的答案;但是我没有发现你的代码有任何问题,除了一个不正确的标记(再次感谢,我删除了表单并创建了另一个,我想这确实是一个不正确的标记,现在正在保存。)嗨,谢谢你的回复,但我不能在这一个中使用php,必须是jsp/html。我确信这是我犯的一些非常愚蠢的错误,也许只是一行代码,但我似乎找不到它!:(
Enumeration reqParams= request.getParameterNames();
while (reqParams.hasMoreElements()) {
String key= (String) reqParams.nextElement();
String val = request.getParameter(element);
System.out.println(" Key ==> "+key+" , Value ==> "+val);
}