loginaction.java~4~

来自「Spring +Web 的完整 MyEclipse 项目源码,使用者可以作为入门」· JAVA~4~ 代码 · 共 65 行

JAVA~4~
65
字号
package loginejb;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;

public class LoginAction
    extends Action {
  public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest servletRequest,
                               HttpServletResponse servletResponse) {
    LoginActionForm loginActionForm = (LoginActionForm) actionForm;

    try{
    //InitialContext ctx=new InitialContext();

    InitialContext ctx= null;

    String url="t3://localhost:7001";
    String user="kingbill";
     String password="10041207";
     Properties properties=null;
    Context context=null;

   try
   {
   properties = new Properties();
   properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
   properties.put(Context.PROVIDER_URL,url);
   properties.put(Context.SECURITY_PRINCIPAL,user);
   properties.put(Context.SECURITY_CREDENTIALS,password);
   ctx = new InitialContext(properties);

   }

   catch(Exception e)
    {
   e.printStackTrace();
    }



    Object ref=ctx.lookup("UserRemote");
    UserHome userhome=(UserHome)PortableRemoteObject.narrow(ref,UserRemoteHome.class);
    userhome.create("bill");



    }
  catch(Exception e){e.printStackTrace();}

    return actionMapping.findForward("success");

  }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?