我在將掃描器輸入到我的Web服務框架中時遇到了一些問題。當我使用輸入掃描儀命令時,它不顯示我想要的結果。嘗試在我的WebService中輸入掃描器輸入以顯示用戶輸入的輸出
我想要發生的是當爲mySponsorID
字符串輸入值時,我希望它顯示在響應或else語句中。例如,如果用戶提示SponsorOrganizationalIdentifier
並且他們進入SOI,我希望他們輸入的內容顯示在響應中。
我是新來的Java和Web服務,所以任何幫助,你可以給我我真的很感激它。下面是代碼:
package org.example.www.newwsdlfile3;
/**
* ExchangeInformationServiceSkeleton java skeleton for the axisService
*/
public class ExchangeInformationServiceSkeleton {
import java.util.Scanner;
/**
* Auto generated method signature
*
* @param hRCtoIRSUpdate
* @return hRCtoIRSUpdateResponse
*/
public org.example.www.newwsdlfile3.HRCtoIRSUpdateResponse hRCtoIRSUpdate(
org.example.www.newwsdlfile3.HRCtoIRSUpdate hRCtoIRSUpdate0) {
HRCtoIRSUpdateResponse hRCtoIRSUpdateResponse = null;
hRCtoIRSUpdateResponse = new HRCtoIRSUpdateResponse();
// get string
String mySponsorID = "";
mySponsorID = hRCtoIRSUpdate0.getSponsorOrganizationalIdentifier();
// check if null
if (mySponsorID == null || mySponsorID.isEmpty()) {
hRCtoIRSUpdateResponse.setErrorCode("The update isn't complete");
hRCtoIRSUpdateResponse.setErrorDescription("SponsorOrganizationIdentifier must have a value");
hRCtoIRSUpdateResponse.setProcessStatus("Update Failed! Please try again!");
// display entry for SponsorOrganizationalIdentifier
} else {
Scanner scan = new Scanner(System.in);
mySponsorID = scan.nextLine();
System.out.println("You have entered " + mySponsorID);
hRCtoIRSUpdateResponse.setProcessStatus("Update Complete!");
hRCtoIRSUpdateResponse.setErrorCode(null);
hRCtoIRSUpdateResponse.setErrorDescription(null);
scan.close();
}
return hRCtoIRSUpdateResponse;
}
}
我看不到你想要的東西:Web服務是在服務器中運行並處理由客戶端發送給它的請求的東西。通常服務器和客戶端是兩個不同的JVM。用戶會在客戶端輸入一些東西。你想在哪裏使用[掃描儀](http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html)以及用於何種目的?來自客戶端的任何數據應該是請求的一部分(在你的情況下是'org.example.www.newwsdlfile3.HRCtoIRSUpdate'對象)。 – hotzst
我想使用else語句中的掃描器。因此,如果mySponsorID不爲null,請寫出用戶在else語句旁邊輸入的內容以及hRCtoIRSUpdateResponse(「更新完成」)。 – barnyak10
我編輯了一段代碼,讓你知道我想做什麼。 – barnyak10