我编写了示例Web服务客户端和服务器,其中服务器将读取文件并将内容存储在字符串中。最后,服务器将该字符串发送给客户端。当我尝试在客户端打印该字符串时,我没有得到输出。遵循服务器代码
@WebMethod(operationName = "createInstance")
public String createInstance() throws IOException {
//TODO write your implementation code here:
String file = "Test.txt";
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append(ls);
}
return stringBuilder.toString();
}
客户端代码
<%
try {
com.student.UnivServiceService service = new com.student.UnivServiceService();
com.student.UnivService port = service.getUnivServicePort();
// TODO process result here
java.lang.String result = port.createInstance();
out.println("Result = "+result.toString());
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
任何人都可以告诉我上述程序的错误。