Search code examples
web-servicesjsptomcat7axis2c

Connect to a Web Service from A JSP Page Using Axis and Tomcat


I am trying to access a web service that I created in Eclipse Indigo. I have all the files, the classes and and the Wsdl file all created. Below is my index.jsp and what happens here is that I return a law company depending on the case and court selected. But What I have failed to find is how to connect to them through a dynamic page i.e. a JSP page. Any advice is highly appreciated

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-   8859-1"%>
<%@ page import="java.net.URL,javax.xml.namespace.QName,java.net.URL,,javax.xml.ws.Service,org.lao.ws.Findlawyers;"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Law Courts Home Page</title>
</head>
<body>
<form action="index.jsp" method="get">
<select name="selectcourt" id="selectcourt">
<option value="concourt">Constitutional Court</option>   
            <option value="highcourt">High Court</option>
            <option value="magcourt">Magistrates Court</option>                
            <option value="supremecourt">Supreme Court</option>
          </select>
            <input type="radio" name="Case Type" value="casecivil" id="CaseType_0" />
            Civil</label>
          <br />
          <label>
            <input type="radio" name="Case Type" value="casecriminal" id="CaseType_1" />
            Criminal</label>

<%              
String casetype = "";
String selcourt = "";
String lawyers  = "";   

%>

<%=lawyers %></th>


</form>
</body>
</html>

Solution

  • You can do it 2 ways,either by sending the form (except for the jsp tags content) to the servlet and dislay the lawyers on a new page or else pass the selected parameters using ajax to the servlet and display the results on the same page.

    Also since you seem to be new to this,its better you try with my first option.Passing a simple form something like this

    <form action="index.jsp" method="get">
    <select name="selectcourt" id="selectcourt">
    <option value="concourt">Constitutional Court</option>   
                <option value="highcourt">High Court</option>
                <option value="magcourt">Magistrates Court</option>                
                <option value="supremecourt">Supreme Court</option>
              </select>
                <input type="radio" name="Case Type" value="casecivil" id="CaseType_0" />
                Civil</label>
              <br />
              <label>
                <input type="radio" name="Case Type" value="casecriminal" id="CaseType_1" />
                Criminal</label>
    
    
    </form>
    

    Then in your servlet retrieve the paramters like this

    String casetype = request.getParamter("Case Type");
    String selcourt =  request.getParamter("selectCourt");
    

    Then use this to find data from database

    Then query use these paramters in a query and get the desired results..