Login.java
上传用户:hgs128
上传日期:2007-02-03
资源大小:166k
文件大小:3k
源码类别:

百货/超市行业

开发平台:

WINDOWS

  1. /*
  2.  * Created on 1999-5-20
  3.  */
  4. package webservice;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7. import java.net.URL;
  8. import javax.servlet.ServletConfig;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.http.HttpServlet;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import org.apache.axis.client.Call;
  14. /**
  15.  * @author 28-9
  16.  *
  17.  * TODO To change the template for this generated type comment go to
  18.  * Window - Preferences - Java - Code Generation - Code and Comments
  19.  */
  20. public class Login extends HttpServlet {
  21. public void init(ServletConfig config) throws ServletException {
  22. super.init(config);
  23. System.out.println("Entering Login.init()");
  24. System.out.println("Leaving Login.init()");
  25. }
  26. public void destroy() {
  27. super.destroy();
  28. }
  29. protected void doGet(HttpServletRequest request,
  30. HttpServletResponse response) throws ServletException, IOException {
  31. processRequest(request,response);
  32. }
  33. /**
  34.  * @param request
  35.  * @param response
  36.  */
  37. private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
  38. System.out.println("Entering Login.processRequest()");
  39. response.setContentType("text/html");
  40. PrintWriter out=response.getWriter();
  41. out.println("<html><title>MyStore Login</title>");
  42. out.println("<body><b><h2>Welcome to MyStore</h2></b></body>");
  43. out.print("<body><h2>Login details: UserID is ");
  44. String username;
  45. try {
  46. username = callWebService();
  47. out.print(username);
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. out.print("</h2></body></html>");
  52. if(out!=null) out.close();
  53. System.out.println("Leaving Login.processRequest()");
  54. }
  55. /**
  56.  * @return
  57.  */
  58. private String callWebService() throws Exception {
  59. Call call=new Call(new URL("http://localhost:8080/axis/services/MyStoreLoginService?wsdl"));
  60. String username=(String)call.invoke("loginUser", new Object[] {new String("danny"),new String("swdandy")});
  61. return username;
  62. //Another way to invoke login method
  63.         // Endpoint is used for making the call
  64. /*        String endpoint = "http://localhost:8080/axis/services/MyStoreLoginService";
  65.         // The Service object is the starting point for accessing the web service.
  66.         Service service = new Service();
  67.         // The call object is used to actually invoke the web service.
  68.         Call call = (Call)service.createCall();
  69.         // Sets the call objects endpoint address
  70.         call.setTargetEndpointAddress(endpoint);
  71.         // Sets the operation name associated with this Call object. 
  72.         call.setOperationName(new QName("loginUser"));
  73.         // Calls the object, passing in the username and passwd. The return value is stored as an object.
  74.         Object returnValue = call.invoke(new Object[] { new String("danny") , new String("swdandy") });
  75.         return (String) returnValue;*/
  76. }
  77. protected void doPost(HttpServletRequest request,
  78. HttpServletResponse response) throws ServletException, IOException {
  79. processRequest(request,response);
  80. }
  81. }