I have a web service in Java and Java client. Client can ask to display particular record based on ID specified. Web service returns the result ok. There is another method "allQuizes" in web services:
@WebMethod(operationName = "allQuizes")
public Collection allQuizes() {
Collection<quizDB> allQuestions = new ArrayList<quizDB>();
try {
Connection con=quizRecords.getConnection();
PreparedStatement ps=con.prepareStatement("SELECT * FROM question");
ResultSet rs=ps.executeQuery();
rs = ps.executeQuery();
while (rs.next()) {
quizDB q = new quizDB();
q.setqId(rs.getInt("qId"));
q.setStatement(rs.getString("statement"));
allQuestions .add(q);
}
rs.close();
con.close();
return allQuestions ;
} catch (SQLException e) {
System.out.println(e);
return null;
}
}
What should i do on Java Client side to display the Collection result? So far I have:
package web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebServiceRef;
import mainpackage.QuizWS_Service;
public class showAllQuestions extends HttpServlet {
@WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/quizWebService/quizWS.wsdl")
private QuizWS_Service service;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("All questions");
}
}
private java.util.List<java.lang.Object> allQuizes() {
mainpackage.QuizWS port = service.getQuizWSPort();
return port.allQuizes();
}
}
Thank you
Aucun commentaire:
Enregistrer un commentaire