📄 imageservlet.java~19~
字号:
package cmp2image;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import java.sql.*;import javax.naming.*;import javax.rmi.PortableRemoteObject;public class ImageServlet extends HttpServlet { private CatalogHome catalogHome; public void init() throws ServletException { } //Process the HTTP Get request public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Flower flower = null; HttpSession session = request.getSession(true); try { Context context = getInitialContext(); //look up jndi name Object ref = context.lookup("Catalog"); //look up jndi name and cast to Home interface catalogHome = (CatalogHome) PortableRemoteObject.narrow(ref, CatalogHome.class); Catalog catalog = catalogHome.create(); String str = request.getParameter("pic"); String name=str.trim(); ArrayList collection = catalog.findOne(name); //ArrayList collection = catalog.findOne("FlowerBlackEyedSusan"); byte[] buf=null; Iterator i = collection.iterator(); while (i.hasNext()) { Object obj = i.next(); if (obj instanceof byte[]) { buf = (byte[]) obj; } } response.getOutputStream().write(buf); getServletContext().getRequestDispatcher("/display.jsp").include(request, response); } catch (Exception ex) { ex.printStackTrace(); } } private Context getInitialContext() throws Exception { String url = "t3://localhost:7001"; String user = null; String password = null; Properties properties = null; try { properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); if (user != null) { properties.put(Context.SECURITY_PRINCIPAL, user); properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password); } return new InitialContext(properties); } catch (Exception e) { System.out.println("Unable to connect to WebLogic server at " + url); System.out.println("Please make sure that the server is running."); throw e; } } //Clean up resources public void destroy() { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -