package beans.login;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import weblogic.jndi.WLInitialContextFactory;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import user.verification.*;
import java.util.Properties;
import java.util.Hashtable;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form1,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String target = new String("valid");
String name=null;
String password=null;
LoginForm form=(LoginForm)form1;
if ( form != null )
{
LoginForm nameForm = (LoginForm)form;
name = nameForm.getUserName();
password=nameForm.getUserPassword();
}
if ( ("".equals(name))||("".equals(password)))
{
target = new String("invalid");
}
else
{
try
{
String initialContextFactory =
"weblogic.jndi.WLInitialContextFactory";
String localContextURL = "t3://localhost:7001";
Properties p = new Properties();
p.put( Context.INITIAL_CONTEXT_FACTORY, initialContextFactory );
p.put( Context.PROVIDER_URL, localContextURL );
Context ctx = new InitialContext(p);
if(ctx==null)
throw new Exception("Failed to load ctx");
else
{
System.out.println("Success loading ctx");
Hashtable hash=ctx.getEnvironment();
System.out.println(hash);
}
Object obj = ctx.lookup("ejb.UserVerificationRemoteHome");
UserVerificationHome tsh = (UserVerificationHome) PortableRemoteObject.narrow(obj,UserVerification.class);
UserVerificationRemote uvr=tsh.create();
if(uvr.verifyUser(name,password))
target="invalid";
}
catch(Exception e)
{
e.printStackTrace();
}
request.setAttribute("UserName", name);
}
return (mapping.findForward(target));
}
}
/* I have added the weblogic.jar file also but there used to be some
Servlet Specification violation issue after that i unziped the the jar file and removed the javax\servlet from the weblogic and made the jar file after the servlet violation issue was resolved.