将java代码移动到jsp

时间:2016-09-28 17:30:58

标签: java html jsp

如何将以下代码移动到jsp页面中,使得println语句的输出在html页面上可见

      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());


}

1 个答案:

答案 0 :(得分:3)

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>