📄 authentificateservlet.java.svn-base
字号:
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sixtwenty.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.ArrayList;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import com.sixtwenty.service.LoginService;
import com.sixtwenty.service.StudentService;
import com.sixtwenty.Projects;
import com.sixtwenty.Submissions;
public class AuthentificateServlet extends HttpServlet
{
//String endpoint = "http://172.23.96.22:8180/axis/services/submit";
String endpoint = "http://localhost:8080/axis/services/submit";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter ();
try {
// Get password and login
String username = new String(request.getParameter("username"));
String password = new String(request.getParameter("password"));
Service service = new Service();
Call call = (Call) service.createCall();
SubmitServiceLocator ssl = new SubmitServiceLocator();
Submit submit = ssl.getsubmit();
Boolean ret = submit.authenticateUser(username, password);
if(ret.booleanValue()) {
String accessLevel = submit.accessLevelOfUser(username);
System.out.println("accessLevel :" +accessLevel);
//Assumption made (access level for staff as 2)
if(accessLevel == 2) {
System.out.println("Staff Login");
String nextJSP = "/jsp/staffpage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
request.getSession().setAttribute("username", username);
request.getSession().setAttribute("password", password);
dispatcher.forward(request, response);
}
//Assumption made (access level for student as 1)
if(accessLevel == 1) {
System.out.println("Student Login");
String nextJSP = "/jsp/studentpage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
request.getSession().setAttribute("username", username);
dispatcher.forward(request, response);
}
if(accessLevel == 3) {
System.out.println("Admin Login");
String nextJSP = "/jsp/adminpage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
request.getSession().setAttribute("username", username);
dispatcher.forward(request, response);
}
} else {
System.out.println("User unknown");
String nextJSP = "/jsp/errorpage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
request.getSession().setAttribute("username", username);
dispatcher.forward(request, response);
}
} catch (Exception e) {
out.println(e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -