你好,我用奇数或偶数来匹配web服务,当我在NetBeans中为web服务创建客户端时,我有这个错误。 这里的Web服务:java.lang.NumberFormatException:对于输入字符串:“添加”
@WebService(serviceName = "Par_Impar")
public class Par_Impar {
/**
* Web service operation
*/
@WebMethod(operationName = "operation")
public String operation(@WebParam(name = "val") int val) {
if(val%2!=0){
//daca reminder-ul nu este 0 este impar
return("IMPAR");
}
else {
//daca reminder-ul este 0 atunci este par
return("PAR");
}
}
}
中的index.jsp:
<html>
<head>
<title>PAGINA JSP</title>
</head>
<body>
<form action="action.jsp" method="post"<br/>
Introdu numarul :<input type="text" name="nr"/><br/>
<input type="submit" value="Testeaza"/>
</form>
</body>
的action.jsp:
<%--
Document : action
Created on : Apr 27, 2013, 5:28:45 PM
Author : ARB
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%-- start web service invocation --%><hr/>
<%
String add=request.getParameter("numar");
int aa=Integer.parseInt("add");
try {
mypack.ParImpar_Service service = new mypack.ParImpar_Service();
mypack.ParImpar port = service.getParImparPort();
// TODO initialize WS operation arguments here
int val=aa;
// TODO process result here
java.lang.String result = port.operation(aa);
out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>
请帮助我。谢谢 !
我试着把int aa = Integer.parseInt(add);这就是我所做的一切,因为我是新手,需要学习很多东西。现在,当我输入一个数字并按下提交按钮来启动Web服务时,结果如下所示:java.lang.NumberFormatException:null。你能告诉我在哪里修改?非常感谢答案!我很感激你在做什么。再次感谢 ! – 2013-04-27 19:00:34
@ AndreiR.Beraru我认为'request.getParameter(“numar”)'这个方法返回'null',所以你得到这个异常。 – 2013-04-29 00:13:06