📄 login.java
字号:
/*
* 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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -