📄 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.Projects;
import com.sixtwenty.Submissions;
import com.sixtwenty.Submit;
import com.sixtwenty.SubmitServiceLocator;
/**
* This servlet is used by authenticate user.
* @author grp-e
*
*/
public class AuthentificateServlet extends HttpServlet
{
//String endpoint = "http://172.23.96.22:8180/axis/services/submit";
String endpoint = "http://localhost:8080/axis/services/submit";
/**
* Handles the get request
* @param request
* @param response
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
doPost(request, response);
}
/**
* Handles the post request
* @param request
* @param 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")); //The username
String password = new String(request.getParameter("password")); //The password
//Instantiate the SubmitServiceLocator
SubmitServiceLocator ssl = new SubmitServiceLocator();
Submit submit = ssl.getsubmit();
//call to remote method authenticateUser
Boolean ret = submit.authenticateUser(username, password);
//Check if the user is authorised user
if(ret.booleanValue()) {
//call to remote method accessLevel
int accessLevel = submit.accessLevel(username);
System.out.println("accessLevel :" +accessLevel);
//access level for staff as 2
if(accessLevel == 2) {
System.out.println("Staff Login");
//Forwarding to next jsp
String nextJSP = "/jsp/staffpage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
//setting the values in session
request.getSession().setAttribute("username", username);
request.getSession().setAttribute("password", password);
dispatcher.forward(request, response);
}
//access level for student as 1
if(accessLevel == 1) {
System.out.println("Student Login");
//Forwarding to next jsp
String nextJSP = "/jsp/studentpage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
//setting the username in session
request.getSession().setAttribute("username", username);
dispatcher.forward(request, response);
}
//access level for admin as 3
if(accessLevel == 3) {
System.out.println("Admin Login");
//Forwarding to next jsp
String nextJSP = "/jsp/adminpage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
//setting the username in session
request.getSession().setAttribute("username", username);
dispatcher.forward(request, response);
}
} else {
System.out.println("User unknown");
//If the user is unauthorised, the system directs to error page
String nextJSP = "/jsp/errorpage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
//setting the username in session
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 + -