⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientviewservlet.java

📁 wap的java实现
💻 JAVA
字号:
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.rmi.*;
import javax.naming.*;
import java.util.*;


public class ClientViewServlet extends HttpServlet
{

	
	ClientHome clientHome;
	
	public void init() throws ServletException
	{
		try
		{
			System.out.println("trying to get initial context");
			Context ic = (InitialContext) getInitialContext();
			System.out.println("Got InitContext");
			Object objRef = ic.lookup("Client");
			System.out.println("Got obj ref");
			clientHome = (ClientHome) PortableRemoteObject.narrow(objRef,ClientHome.class);
			System.out.println("Got Home");
		}catch(Exception e)
		{
			System.out.println("Error in init");
			e.printStackTrace();
		}
	}
	
	public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
	{
		
		try
		{
			HttpSession session = req.getSession(false);
			String strSalesmanId = (String)session.getAttribute("SalesmanId");
			System.out.println("salesman id: " + strSalesmanId);
			Collection clients = clientHome.findBySalesman(strSalesmanId);
			if(clients.size() <= 0)
			{
				System.out.println("Clients size: " + clients.size());
				res.sendRedirect(res.encodeURL("/Status.jsp?code=3"));
			}
			Vector cinfo[] = new Vector[clients.size()];
			System.out.println("length of client list: " + clients.size());
			Iterator i = clients.iterator();
			int cnt=0;
			System.out.println("Beginning search");

			while(i.hasNext())
			{
				
				Client client = (Client) i.next();
				cinfo[cnt] = new Vector(3);
				cinfo[cnt].add(client.getId());
				cinfo[cnt].add(client.getName());
				cinfo[cnt].add(client.getAddress());
				cnt++;
			
			}
			session.setAttribute("ClientList",cinfo);
			res.sendRedirect(res.encodeURL("/ClientList.jsp"));
		}catch(Exception e){
			System.out.println("Error while obtaining client list:" + e.getMessage());
			res.sendRedirect(res.encodeURL("/Status.jsp?code=1"));

		}
	}
	
	private Context getInitialContext() throws NamingException
    {
    	Properties h = null;
    	try {
      // Get an InitialContext
      	h = new Properties();
      	h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
	      h.put(Context.PROVIDER_URL, "t3://localhost:7001");
      	
	      
    	}catch(Exception ne) {
      	System.out.println("Unable to get an initial context");
    	}
		return new InitialContext(h);   
   }

}

⌨️ 快捷键说明

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