facebook

How jsp invoke Webservice ?

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #269842 Reply

    lovevhvlove
    Member

    I did example http://myeclipseide.com/enterpriseworkbench/help/index.jsp?topic=/com.genuitec.myeclipse.doc/html/quickstarts/webservices/index.html ( create the first web service). It worked fine. I also modified argument. It works as well. However, I don’t know how to let JSP invoke web service. Can you provide me a JSP code to invoke and retrieve “Hello World” from the example Web Service link above. I tried like code below. It doesn’t work

    <%@ page language=”java” pageEncoding=”ISO-8859-1″%>

    <%@ taglib uri=”http://struts.apache.org/tags-bean&#8221; prefix=”bean” %>
    <%@ taglib uri=”http://struts.apache.org/tags-html&#8221; prefix=”html” %>
    <%@ taglib uri=”http://struts.apache.org/tags-logic&#8221; prefix=”logic” %>
    <%@ taglib uri=”http://struts.apache.org/tags-tiles&#8221; prefix=”tiles” %>

    <%@page import=”org.apache.axis.client.Call,

    org.apache.axis.client.Service,org.apache.axis.encoding.XMLType,

    javax.xml.rpc.ParameterMode” %>

    <% String endpoint =

    http://localhost:8080/HelloWorld/services/HelloWorldService?WSDL&#8221;;

    Service service = new Service();

    Call call = (Call) service.createCall();

    call.setTargetEndpointAddress(new java.net.URL(endpoint));

    call.setOperationName(“example”);

    //call.setProperty(Call.NAMESPACE, “http://DefaultNamespace&#8221;);

    call.addParameter(“in0”, XMLType.XSD_STRING, ParameterMode.IN);
    // call.PARAM_MODE_IN);
    call.setReturnType( XMLType.XSD_STRING );%>

    <%=call.invoke(new Object[] {“Hello!”})%>

    This is error return:

    HTTP Status 500 –

    ——————————————————————————–

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: Unable to compile class for JSP:

    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.

    #269852 Reply

    Riyad Kalla
    Member

    Moving OT > Soft Dev

    #269883 Reply

    lovevhvlove
    Member

    HIc… Does anyone help me ? Thank very much

    #269898 Reply

    lovevhvlove
    Member

    I created a Web Service Client as New/Other/MyEclipse/Web Service/Web Service Client. Then I create a JSP as below. It doesn’t work . Can anyone help me? Plz.

    <%@ page import=”javax.xml.rpc.Stub,javax.xml.rpc.*,javax.naming.*,javax.jws.*,org.codehaus.xfire.service.*,defaultnamespace.*”%>
    <html>
    <head>
    <title>Hello</title>
    </head>
    <body bgcolor=”#ffcccc”>
    <h2>
    Welcome to the Math Web Service
    </h2>
    <form method=”get”>
    <input type=”text” name=”num1″ size=”25″>
    <p></p>
    <input type=”text” name=”num2″ size=”25″ value=”5″>
    <p></p>
    <input type=”submit” value=”AddNumbers”>
    <input type=”reset” value=”Reset”>
    </form>

    <%
    String str1 = request.getParameter(“num1”);
    String str2 = request.getParameter(“num2″);
    if ( str1 != null && str2 != null ) {
    %>
    <%
    String result=””;
    try {
    // Create a stub object
    Stub stub = (Stub)(new HelloVanServiceClient().getHelloVanServiceHttpPort());

    // Set the endpoint address the stub uses to access the service
    stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
    http://localhost:8080/HelloVan/services/HelloVanService?WSDL&#8221;);
    // Cast the stub to MathFace
    HelloVanServicePortType action= (HelloVanServicePortType)stub;
    // HelloVanServiceHttp action = (HelloVanServiceHttp)stub;
    // Retrieve and parse the parameters from the request message
    // Invoke the method
    result = action.example(str1);

    } catch (Exception ex) {
    }

    }
    %>

    </body>
    </html>

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: How jsp invoke Webservice ?

You must be logged in to post in the forum log in