I am having a Webservice running in Tomcat server. It gets input from the user and appends hello to it. Now, I want this Hello + entered input to be displayed in a jsp page. Is it possible to send the value from the java program to the jsp page directly. If so please tell me how this can be done ?
Any help or sample program would be highly appreciated.
Attaching my java code here
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService
public class Hello {
private String message = new String("Hello, ");
String name1;
public Hello() {
}
@WebMethod
public String sayHello(String name) throws Exception {
this.name1 = name;
System.out.println("The value of name1 is " + name1);
return message + name + ".";
}
}
Thanks,
It's not possible and here's why:
The web service call is an XML-formatted SOAP message sent to your web service. The client calling your web service is doing so, with the expectation that a similarly-formatted web service response is going to be sent back. What you are asking here is that rather than sending the expected XML-formatted SOAP response that you've promised your web service client (by way of publishing a WSDL), you're going to send back an HTML document instead. See the problem?
Bottom line : You cannot respond to a SOAP request with an HTML (or JSP-generated HTML) response
Getting the user input from the first page:
String userInput = request.getParameter("userInput");
In the java code to forward data to the asp file
String url = "/WEB-INF/JSP/display.jsp"; //Assumes this exists
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
request.setAttribute("userInput", userInput);
rd.forward(request,response);
In the JSP
<%
String userInput = (String) request.getAttribute("userInput");
%>
To print it in the JSP
<h1><%=userInput%></h1>
EDIT: My apologies, my first answer was pertaining to Apache Tomcat not jws.
See this section of this guide: Developing a Web client for Calculator
It appears as though you simply forward the form action on the initial HTML page to a separate results page which will make use of the web service you have created.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.