List of usage examples for javax.servlet ServletException ServletException
public ServletException(Throwable rootCause)
From source file:DbServletTrans.java
public void init() throws ServletException { Context env = null;//from ww w . j a v a 2 s .c om try { env = (Context) new InitialContext().lookup("java:comp/env"); pool = (DataSource) env.lookup("jdbc/oracle-8i-athletes"); if (pool == null) throw new ServletException("'oracle-8i-athletes' is an unknown DataSource"); } catch (NamingException ne) { throw new ServletException(ne); } }
From source file:BeanServlet.java
public void init() throws ServletException { Context env = null;// w w w . jav a 2 s .com try { // Compile error since there is no StockPriceBean.class // change the name according to your requirements env = (Context) new InitialContext().lookup("java:comp/env"); spbean = (StockPriceBean) env.lookup("bean/pricebean"); //close the InitialContext env.close(); if (spbean == null) throw new ServletException("bean/pricebean is an unknown JNDI object"); } catch (NamingException ne) { try { env.close(); } catch (NamingException nex) { } throw new ServletException(ne); } }
From source file:DbMetaServlet.java
public void init() throws ServletException { Context env = null;/* w w w . j av a 2 s . com*/ try { env = (Context) new InitialContext().lookup("java:comp/env"); pool = (DataSource) env.lookup("jdbc/oracle-8i-athletes"); if (pool == null) throw new ServletException("'oracle-8i-athletes' is an unknown DataSource"); } catch (NamingException ne) { throw new ServletException(ne); } }
From source file:de.dominikschadow.javasecurity.csrf.CSRFTokenHandler.java
public static String getToken(HttpSession session) throws ServletException, NoSuchAlgorithmException, NoSuchProviderException { if (session == null) { throw new ServletException(MISSING_SESSION); }/* w ww. ja va2s . co m*/ String token = (String) session.getAttribute(CSRF_TOKEN); if (StringUtils.isEmpty(token)) { token = getToken(); session.setAttribute(CSRF_TOKEN, token); } return token; }
From source file:com.tbodt.jswerve.servlet.JSwerveServlet.java
@Override public void init() throws ServletException { ServletContext ctx = getServletContext(); Set<Class<?>> classes = new HashSet<Class<?>>(); spiderWar(ctx, "/WEB-INF/classes", classes); try {/* ww w . ja va 2 s .c o m*/ website = new Website(classes); } catch (InvalidWebsiteException ex) { throw new ServletException(ex); } }
From source file:WeblogicDbServlet.java
public void init() throws ServletException { Context env = null;/*from ww w. java 2s .c o m*/ Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); //ht.put(Context.PROVIDER_URL,"t3://localhost:7001"); try { env = new InitialContext(ht); pool = (javax.sql.DataSource) env.lookup("oracle-8i-athletes"); if (pool == null) throw new ServletException("'oracle-8i-athletes' is an unknown DataSource"); } catch (NamingException ne) { throw new ServletException(ne); } }
From source file:kwashc.blog.database.Database.java
public static Comment getComment(int ID) throws ServletException { for (Comment comment : comments) { if (ID == comment.getID()) { return comment; }/* w ww. j a v a 2 s . c o m*/ } throw new ServletException("Comment with ID=" + ID + " not found. Program error or failed attack?"); }
From source file:org.akhikhl.examples.gretty.hellogretty.ExampleServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); try {/* w w w . ja v a 2 s .c om*/ out.println("<h1>Hello, world!" + (dataSource != null ? dataSource.getConnection() : "null") + "</h1>"); out.flush(); } catch (SQLException ex) { throw new ServletException(ex); } finally { out.close(); } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.json.GetEntitiesByVClassContinuation.java
@Override protected JSONArray process() throws ServletException { log.debug("in getEntitiesByVClassContinuation()"); String resKey = vreq.getParameter("resultKey"); if (resKey == null) throw new ServletException("Could not get resultKey"); HttpSession session = vreq.getSession(); if (session == null) throw new ServletException("there is no session to get the pervious results from"); @SuppressWarnings("unchecked") List<Individual> entsInVClass = (List<Individual>) session.getAttribute(resKey); if (entsInVClass == null) throw new ServletException("Could not find List<Individual> for resultKey " + resKey); List<Individual> entsToReturn = new ArrayList<Individual>(REPLY_SIZE); boolean more = false; int count = 0; /* we have a large number of items to send back so we need to stash the list in the session scope */ if (entsInVClass.size() > REPLY_SIZE) { more = true;/*from w ww. j a v a 2 s . c o m*/ ListIterator<Individual> entsFromVclass = entsInVClass.listIterator(); while (entsFromVclass.hasNext() && count <= REPLY_SIZE) { entsToReturn.add(entsFromVclass.next()); entsFromVclass.remove(); count++; } if (log.isDebugEnabled()) log.debug("getEntitiesByVClassContinuation(): Creating reply with continue token," + " sending in this reply: " + count + ", remaing to send: " + entsInVClass.size()); } else { //send out reply with no continuation entsToReturn = entsInVClass; count = entsToReturn.size(); session.removeAttribute(resKey); if (log.isDebugEnabled()) log.debug("getEntitiesByVClassContinuation(): sending " + count + " Ind without continue token"); } //put all the entities on the JSON array JSONArray ja = individualsToJson(entsToReturn); //put the responseGroup number on the end of the JSON array if (more) { try { JSONObject obj = new JSONObject(); obj.put("resultGroup", "true"); obj.put("size", count); StringBuffer nextUrlStr = vreq.getRequestURL(); nextUrlStr.append("?").append("getEntitiesByVClass").append("=1&").append("resultKey=") .append(resKey); obj.put("nextUrl", nextUrlStr.toString()); ja.put(obj); } catch (JSONException je) { throw new ServletException(je.getMessage()); } } log.debug("done with getEntitiesByVClassContinuation()"); return ja; }
From source file:com.java2s.SendFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException { //get the file name from the 'file' parameter String fileName = request.getParameter("file"); if (fileName == null || fileName.equals("")) throw new ServletException("Invalid or non-existent file parameter in SendPdf component."); if (fileName.indexOf(".pdf") == -1) fileName = fileName + ".pdf"; ServletOutputStream stream = null;/* w w w .j av a2s . c o m*/ BufferedInputStream buf = null; HttpServletResponse httpResp = null; try { httpResp = (HttpServletResponse) response; stream = httpResp.getOutputStream(); File pdf = new File(PDF_DIR + "/" + fileName); //set response headers httpResp.setContentType(PDF_CONTENT_TYPE); httpResp.addHeader("Content-Disposition", "attachment; filename=" + fileName); httpResp.setContentLength((int) pdf.length()); FileInputStream input = new FileInputStream(pdf); buf = new BufferedInputStream(input); int readBytes = 0; //read from the file; write to the ServletOutputStream while ((readBytes = buf.read()) != -1) stream.write(readBytes); } catch (Exception ioe) { // throw new ServletException(ioe.getMessage()); System.out.println(ioe.getMessage()); } finally { if (buf != null) buf.close(); if (stream != null) { stream.flush(); //stream.close(); } } //end finally chain.doFilter(request, httpResp); }