Login.java
资源名称:MyStore.rar [点击查看]
上传用户:hgs128
上传日期:2007-02-03
资源大小:166k
文件大小:3k
源码类别:
百货/超市行业
开发平台:
WINDOWS
- /*
- * Created on 1999-5-20
- */
- package webservice;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.net.URL;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.axis.client.Call;
- /**
- * @author 28-9
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
- public class Login extends HttpServlet {
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- System.out.println("Entering Login.init()");
- System.out.println("Leaving Login.init()");
- }
- public void destroy() {
- super.destroy();
- }
- protected void doGet(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- processRequest(request,response);
- }
- /**
- * @param request
- * @param response
- */
- private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
- System.out.println("Entering Login.processRequest()");
- response.setContentType("text/html");
- PrintWriter out=response.getWriter();
- out.println("<html><title>MyStore Login</title>");
- out.println("<body><b><h2>Welcome to MyStore</h2></b></body>");
- out.print("<body><h2>Login details: UserID is ");
- String username;
- try {
- username = callWebService();
- out.print(username);
- } catch (Exception e) {
- e.printStackTrace();
- }
- out.print("</h2></body></html>");
- if(out!=null) out.close();
- System.out.println("Leaving Login.processRequest()");
- }
- /**
- * @return
- */
- private String callWebService() throws Exception {
- Call call=new Call(new URL("http://localhost:8080/axis/services/MyStoreLoginService?wsdl"));
- String username=(String)call.invoke("loginUser", new Object[] {new String("danny"),new String("swdandy")});
- return username;
- //Another way to invoke login method
- // Endpoint is used for making the call
- /* String endpoint = "http://localhost:8080/axis/services/MyStoreLoginService";
- // The Service object is the starting point for accessing the web service.
- Service service = new Service();
- // The call object is used to actually invoke the web service.
- Call call = (Call)service.createCall();
- // Sets the call objects endpoint address
- call.setTargetEndpointAddress(endpoint);
- // Sets the operation name associated with this Call object.
- call.setOperationName(new QName("loginUser"));
- // Calls the object, passing in the username and passwd. The return value is stored as an object.
- Object returnValue = call.invoke(new Object[] { new String("danny") , new String("swdandy") });
- return (String) returnValue;*/
- }
- protected void doPost(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- processRequest(request,response);
- }
- }