2016-09-28 88 views
-1

如何移動下面的代碼到JSP頁面中做一個HTML頁面上可見的println語句的輸出移動Java代碼的jsp

 package com.siebel.WebService; 
    import org.apache.axis.message.SOAPHeaderElement; 
import javax.xml.soap.SOAPElement; 
import java.lang.Object; 
public class Tester { 

public static void main(String[] argv) throws Exception { 
    SR_spcWeb_spcService srv=new UNINServiceRequestWSLocator().getSR_spcWeb_spcService(new java.net.URL("https://crmsit.un.org/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1")); 
((SR_spcWeb_spcServiceStub)srv).setUsername("username"); 
((SR_spcWeb_spcServiceStub)srv).setPassword("password"); 
((SR_spcWeb_spcServiceStub)srv).setHeader("http://siebel.com/webservices", "UsernameToken","username"); 
((SR_spcWeb_spcServiceStub)srv).setHeader("http://siebel.com/webservices", "PasswordText","password"); 
((SR_spcWeb_spcServiceStub)srv).setHeader("http://siebel.com/webservices", "SessionType","Stateless"); 
QuerySR_Input sr=new QuerySR_Input("RFS-1-339103333"); 
QuerySR_Output srvo= srv.querySR(sr); 
System.out.println("Got from web service="+srvo.getStatusCode()+srvo.getSource()+srvo.getAlternateServiceLocation()+srvo.getActualStartDate()+srvo.getAlternateContactName()+srvo.getAlternateEmailAddress()); 
System.out.println("Got from web service="+srvo.getAlternatePhone()+srvo.getArea()+srvo.getAssetAdditionalComments()+srvo.getAssetMake()+srvo.getAssetModel()); 
System.out.println("Got from web service="+srvo.getAssetNum()+srvo.getAssetType()+srvo.getBarcode()+srvo.getDescription()+srvo.getImpact()+srvo.getOnBehalfOfBadge()); 
System.out.println("Got from web service="+srvo.getOnBehalfOfIndex()+srvo.getOnBehalfOfMissionID()+srvo.getPointofContact()); 


} 
+0

我感動的代碼成爲一個servlet做一個AJAX調用這個servlet。但阿賈克斯呼籲失敗。這是一個正確的方法嗎? –

+4

*不要*將代碼移入JSP;它被稱爲「scriptlets」,這是一個噩夢來處理。使用類似Spring MVC的將結果傳遞給JSP(或Thymeleaf)的東西,它只顯示結果。 – chrylis

回答

2

JavaServerPages(JSP)是一種技術,可以幫助基於HTML,XML等創建動態生成的網頁。

您可以在HTML標籤內使用<% %>標籤來插入JAVA代碼。

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
</head> 
<body> 
    <% 
     SR_spcWeb_spcService srv = new UNINServiceRequestWSLocator().getSR_spcWeb_spcService(new java.net.URL("https://crmsit.un.org/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1")); 
     ((SR_spcWeb_spcServiceStub) srv).setUsername("username"); 
     ((SR_spcWeb_spcServiceStub) srv).setPassword("password"); 
     ((SR_spcWeb_spcServiceStub) srv).setHeader("http://siebel.com/webservices", "UsernameToken", "username"); 
     ((SR_spcWeb_spcServiceStub) srv).setHeader("http://siebel.com/webservices", "PasswordText", "password"); 
     ((SR_spcWeb_spcServiceStub) srv).setHeader("http://siebel.com/webservices", "SessionType", "Stateless"); 
     QuerySR_Input sr = new QuerySR_Input("RFS-1-339103333"); 
     QuerySR_Output srvo = srv.querySR(sr); 
     out.println("Got from web service=" + srvo.getStatusCode() + srvo.getSource() + srvo.getAlternateServiceLocation() + srvo.getActualStartDate() + srvo.getAlternateContactName() + srvo.getAlternateEmailAddress()); 
     out.println("Got from web service=" + srvo.getAlternatePhone() + srvo.getArea() + srvo.getAssetAdditionalComments() + srvo.getAssetMake() + srvo.getAssetModel()); 
     out.println("Got from web service=" + srvo.getAssetNum() + srvo.getAssetType() + srvo.getBarcode() + srvo.getDescription() + srvo.getImpact() + srvo.getOnBehalfOfBadge()); 
     out.println("Got from web service=" + srvo.getOnBehalfOfIndex() + srvo.getOnBehalfOfMissionID() + srvo.getPointofContact()); 
    %> 
</body>