?? authenticationservlet.java
字號:
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* http://www.opensource.org/licenses/cddl1.php. If
* applicable, add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced
* with your own identifying information:
* Portions Copyright [yyyy]
* [name of copyright owner]
*/
/*
* $(@)AuthenticationServlet.java $Revision: 1.2 $ $Date: 2006/07/24 21:58:58 $
*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
*/
package com.sun.sjc.idtv.vod.server.http;
import javax.servlet.*;
import javax.servlet.http.*;
import com.sun.sjc.idtv.vod.server.subscriber.*;
import javax.naming.*;
import javax.rmi.*;
import com.sun.sjc.idtv.vod.shared.data.*;
public class AuthenticationServlet extends HttpServlet {
InitialContext initContext = null;
SubscriberManagementSystem sms;
SubscriberManagementSystemHome smsHome;
public void init(ServletConfig config) throws ServletException {
try {
super.init(config);
initContext = new javax.naming.InitialContext();
String JNDIName = "java:comp/env/ejb/SubscriberManagementSystem";
Object objref = initContext.lookup(JNDIName);
smsHome = (SubscriberManagementSystemHome)PortableRemoteObject.narrow(objref, SubscriberManagementSystemHome.class);
sms = smsHome.create();
}
catch(Exception e) {
e.printStackTrace();
}
}
public void destroy() {
smsHome = null;
sms = null;
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
String username = request.getParameter("username");
String password = request.getParameter("password");
try {
Subscriber[] subs = sms.getSubscriberList("127.0.0.1");
for(int i=0;i<subs.length; i++) {
if(subs[i].firstname.equals(username)) {
Subscriber subb = null;
try {
subs[i].pin = password;
subb = sms.authenticate((Subscriber) subs[i]);
}
catch(Exception e2) {
e2.printStackTrace();
}
if(subb != null ) {
// Login successful
System.out.println("AuthenticationServlet: Login successful");
request.getSession().setAttribute("userid",username);
request.getSession().setAttribute("subscriber",subb);
//getServletContext().getRequestDispatcher(response.encodeURL("/MovieCatalog.jsp")).forward(request,response);
//getServletContext().getRequestDispatcher(response.encodeURL("/StoredSessions.jsp")).forward(request,response);
getServletContext().getRequestDispatcher(response.encodeURL("/MainMenu.jsp")).forward(request,response);
}
else {
// Login failed
getServletContext().getRequestDispatcher(response.encodeURL("/login.jsp")).forward(request,response);
}
}
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -