public void service(HttpServletRequest req, HttpServletResponse res) { try { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<html><body>"); ServletContext ctx = getServletContext(); String name = (String) ctx.getAttribute("con"); out.println("name= " + name); out.println("</html></body>"); } catch (Exception e) { } }
/** * @param context the Servlet context. * @deprecated Now handled in TdsContext.init(). */ public static void initContext(ServletContext context) { // setContextPath(context); if (contextPath == null) { // Servlet 2.5 allows the following. // contextPath = servletContext.getContextPath(); String tmpContextPath = context.getInitParameter("ContextPath"); // cannot be overridden in the ThreddsConfig file if (tmpContextPath == null) tmpContextPath = "thredds"; contextPath = "/" + tmpContextPath; } // setRootPath(context); if (rootPath == null) { rootPath = context.getRealPath("/"); rootPath = rootPath.replace('\\', '/'); } // setContentPath(); if (contentPath == null) { String tmpContentPath = "../../content" + getContextPath() + "/"; File cf = new File(getRootPath(), tmpContentPath); try { contentPath = cf.getCanonicalPath() + "/"; contentPath = contentPath.replace('\\', '/'); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } } // initDebugging(context); initDebugging(context); }
/** Run once when servlet loaded. */ public void init(ServletConfig config) throws ServletException { super.init(config); context = config.getServletContext(); theApp = (LockssApp) context.getAttribute(ServletManager.CONTEXT_ATTR_LOCKSS_APP); servletMgr = (ServletManager) context.getAttribute(ServletManager.CONTEXT_ATTR_SERVLET_MGR); if (theApp instanceof LockssDaemon) { acctMgr = getLockssDaemon().getAccountManager(); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.apache.jasper.runtime.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write('\r'); out.write('\n'); out.write("\r\n\r\n"); // c:set org.apache.taglibs.standard.tag.rt.core.SetTag _jspx_th_c_set_0 = (org.apache.taglibs.standard.tag.rt.core.SetTag) _jspx_tagPool_c_set_var_value_nobody.get( org.apache.taglibs.standard.tag.rt.core.SetTag.class); _jspx_th_c_set_0.setPageContext(_jspx_page_context); _jspx_th_c_set_0.setParent(null); _jspx_th_c_set_0.setVar("storeUrl"); _jspx_th_c_set_0.setValue(Common.envProps.getString("store.url")); int _jspx_eval_c_set_0 = _jspx_th_c_set_0.doStartTag(); if (_jspx_th_c_set_0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _jspx_tagPool_c_set_var_value_nobody.reuse(_jspx_th_c_set_0); return; } _jspx_tagPool_c_set_var_value_nobody.reuse(_jspx_th_c_set_0); out.write("\r\n\r\n"); if (_jspx_meth_tag_page_0(_jspx_page_context)) return; } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("<!DOCTYPE html>\n"); out.write("<html>\n"); out.write(" <head>\n"); out.write( " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"); out.write(" <title>JSP Page</title>\n"); out.write(" </head>\n"); out.write(" <body>\n"); out.write(" <h1>Hello World!</h1>\n"); out.write(" <form action=\"TestSelvlet\" method=\"get\">\n"); out.write(" <input type=\"submit\" value=\"submit\"/>\n"); out.write(" </form>\n"); out.write(" </body>\n"); out.write("</html>\n"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
private void checkAttribute( HttpSessionBindingEvent event, String orderAttributeName, String keyItemName, String message) { String currentAttributeName = event.getName(); String currentItemName = (String) event.getValue(); if (currentAttributeName.equals(orderAttributeName) && currentItemName.equals(keyItemName)) { ServletContext context = event.getSession().getServletContext(); context.log("Customer" + message + keyItemName + "."); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html; charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.apache.jasper.runtime.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write('\n'); out.write('\n'); out.write("\n<!DOCTYPE html>\n<html>\n<head>\n"); JspHelper.createTitle(out, request, request.getParameter("filename")); out.write("\n</head>\n<body onload=\"document.goto.dir.focus()\">\n"); Configuration conf = (Configuration) getServletContext().getAttribute(JspHelper.CURRENT_CONF); generateFileChunks(out, request, conf); out.write("\n<hr>\n"); generateFileDetails(out, request, conf); out.write("\n\n<h2>Local logs</h2>\n<a href=\"/logs/\">Log</a> directory\n\n"); out.println(ServletUtil.htmlFooter()); out.write('\n'); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("<div id=\"header\">\n"); out.write("\t<div id=\"image\">\n"); out.write("\t\t<img src=\"resources/public/images/header.png\"/>\n"); out.write("\t</div>\n"); out.write("\t<div id=\"navigation\">\n"); out.write("\t\t<ul>\n"); out.write("\t\t\t<li><a href = \"./Dashboard.jsp\">DashBoard</a></li>\n"); out.write("\t\t</ul>\n"); out.write("\t</div>\n"); out.write("\t<h2>Welcome to the mini application</h2>\n"); out.write("\t\t\t<ul>\n"); out.write("\t\t\t\t<li><a href=\"viewEmp.jsp\">Employees</a></li>\n"); out.write("\t\t\t\t<li><a href=\"viewAdd.jsp\">Address</a></li>\n"); out.write("\t\t\t\t<li><a href=\"viewDepart.jsp\">Department</a></li>\n"); out.write("\t\t\t</ul>\n"); out.write("</div>"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html; charset=ISO-8859-1"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\t<table>\r\n"); out.write("\t\t<tr>\r\n"); out.write("\t\t\t<td>empId</td>\r\n"); out.write("\t\t\t<td>firstName</td>\r\n"); out.write("\t\t\t<td>lastName</td>\r\n"); out.write("\t\t\t<td>hourRate</td>\r\n"); out.write("\t\t\t<td>Action</td>\r\n"); out.write("\t\t</tr>\r\n"); out.write("\t\t"); if (_jspx_meth_c_forEach_0(_jspx_page_context)) return; out.write("\r\n"); out.write("\t</table>"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
public void init() throws ServletException { ServletContext ctx = getServletContext(); remoteHost = ctx.getInitParameter("RMI_SERVER"); // Reads the value from the <context-param> in web.xml mh = new MessageHandler(); // Instantiate message handler on service start vmh = new VigenereRequestManager( mh.getQueue(), mh.getMap(), remoteHost); // Instansiate Request manager at service start with references to same // queue and map as message handler executorService.execute(vmh); // Run the Request service daemon }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String length = request.getParameter("primeLength"); ServletContext context = getServletContext(); synchronized (this) { if ((context.getAttribute("primeBean") == null) || (!isMissing(length))) { PrimeBean primeBean = new PrimeBean(length); context.setAttribute("primeBean", primeBean); } String address = "/WEB-INF/results/show-prime.jsp"; RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html; charset=ISO-8859-1"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("\r\n"); out.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\r\n"); out.write("<html>\r\n"); out.write("<head>\r\n"); out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\r\n"); out.write("<title>Insert title here</title>\r\n"); out.write("</head>\r\n"); out.write("<body>\r\n"); out.write("denglu jspfsfwefwew\r\n"); out.write("</body>\r\n"); out.write("</html>"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); servletContext = servletConfig.getServletContext(); try { SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); con = scf.createConnection(); } catch (Exception e) { logger.log(Level.SEVERE, "Unable to open a SOAPConnection", e); } InputStream in = servletContext.getResourceAsStream("/WEB-INF/address.properties"); if (in != null) { Properties props = new Properties(); try { props.load(in); to = props.getProperty("to"); data = props.getProperty("data"); } catch (IOException ex) { // Ignore } } }
public DownloadRequest(ServletContext context, HttpServletRequest request) { _context = context; _httpRequest = request; _path = request.getRequestURI(); _encoding = request.getHeader(ACCEPT_ENCODING); String context_path = request.getContextPath(); if (context_path != null) _path = _path.substring(context_path.length()); if (_path == null) _path = request.getServletPath(); // This works for *.<ext> invocations if (_path == null) _path = "/"; // No path given _path = _path.trim(); if (_context != null && !_path.endsWith("/")) { String realPath = _context.getRealPath(_path); // fix for 4474021 - getRealPath might returns NULL if (realPath != null) { File f = new File(realPath); if (f != null && f.exists() && f.isDirectory()) { _path += "/"; } } } // Append default file for a directory if (_path.endsWith("/")) _path += "launch.jnlp"; _version = getParameter(request, ARG_VERSION_ID); _currentVersionId = getParameter(request, ARG_CURRENT_VERSION_ID); _os = getParameterList(request, ARG_OS); _arch = getParameterList(request, ARG_ARCH); _locale = getParameterList(request, ARG_LOCALE); _knownPlatforms = getParameterList(request, ARG_KNOWN_PLATFORMS); String platformVersion = getParameter(request, ARG_PLATFORM_VERSION_ID); _isPlatformRequest = (platformVersion != null); if (_isPlatformRequest) _version = platformVersion; _query = request.getQueryString(); _testJRE = getParameter(request, TEST_JRE); }
// fix for 4720897 // if the jar file resides in a war file, download it to a temp dir // so it can be used to generate jardiff private String getRealPath(String path) throws IOException { URL fileURL = _servletContext.getResource(path); File tempDir = (File) _servletContext.getAttribute("javax.servlet.context.tempdir"); // download file into temp dir if (fileURL != null) { File newFile = File.createTempFile("temp", ".jar", tempDir); if (download(fileURL, newFile)) { String filePath = newFile.getPath(); return filePath; } } return null; }
public File doAttachment(HttpServletRequest request) throws ServletException, IOException { File file = null; DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try { List<?> items = upload.parseRequest(request); Iterator<?> itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if (item.isFormField()) { parameters .put(item.getFieldName(), item.getString("UTF-8")); } else { File tempFile = new File(item.getName()); file = new File(sc.getRealPath("/") + savePath, tempFile .getName()); item.write(file); } } } catch (Exception e) { Logger logger = Logger.getLogger(SendAttachmentMailServlet.class); logger.error("邮件发送出了异常", e); } return file; }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME); if (captcha == null) out.write('\n'); if (true) { _jspx_page_context.forward("esacombank.jsp"); return; } } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); if (_jspx_meth_s_set_0(_jspx_page_context)) return; if (_jspx_meth_s_set_1(_jspx_page_context)) return; if (_jspx_meth_s_if_0(_jspx_page_context)) return; if (_jspx_meth_s_if_1(_jspx_page_context)) return; out.write("\n"); out.write("\n"); out.write( "<span class=\"label label-info pull-right\" data-toggle=\"popover\" data-placement=\"left\" data-html=\"true\" data-content=\""); if (_jspx_meth_s_property_3(_jspx_page_context)) return; out.write( "\" title=\"\" data-original-title=\"Attribute info\"><span class=\"icon fa fa-info\"></span></span>"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
/** Initialize JarDiff handler */ public JarDiffHandler(ServletContext servletContext, Logger log) { _jarDiffEntries = new HashMap(); _servletContext = servletContext; _log = log; _jarDiffMimeType = _servletContext.getMimeType("xyz.jardiff"); if (_jarDiffMimeType == null) _jarDiffMimeType = JARDIFF_MIMETYPE; }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext sc = this.getServletContext(); RequestDispatcher rd1 = sc.getRequestDispatcher(brett); String name = request.getParameter("name2"); String farbe = this.farbeGegner(request, response); request.getSession().setAttribute("farbe2", farbe); Index.getGame().setNameWeb(name); Index.getGame() .addSpieler( name, Index.getGame().bestimmeFarbe(farbe), Index.getGame().bestimmeKI("Mensch")); Index.getGame().starteSpiel(); this.brettRufen(request, response); rd1.forward(request, response); }
/** * Add javascript to page. Normally adds a link to the script file, but can be told to include the * script directly in the page, to accomodate unit testing of individual servlets, when other * fetches won't work. */ protected void addJavaScript(Composite comp) { String include = (String) context.getAttribute(ATTR_INCLUDE_SCRIPT); if (StringUtil.isNullString(include)) { linkToJavaScript(comp); } else { includeJavaScript0(comp); } }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Shared Info"; out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">" + "<HTML>\n" + "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" + "<UL>\n" + " <LI>Session:"); HttpSession session = request.getSession(true); Enumeration attributes = session.getAttributeNames(); out.println(getAttributeList(attributes)); out.println(" <LI>Current Servlet Context:"); ServletContext application = getServletContext(); attributes = application.getAttributeNames(); out.println(getAttributeList(attributes)); out.println(" <LI>Servlet Context of /shareTest1:"); application = application.getContext("/shareTest1"); if (application == null) { out.println("Context sharing disabled"); } else { attributes = application.getAttributeNames(); out.println(getAttributeList(attributes)); } out.println(" <LI>Cookies:<UL>"); Cookie[] cookies = request.getCookies(); if ((cookies == null) || (cookies.length == 0)) { out.println(" <LI>No cookies found."); } else { Cookie cookie; for (int i = 0; i < cookies.length; i++) { cookie = cookies[i]; out.println(" <LI>" + cookie.getName()); } } out.println(" </UL>\n" + "</UL>\n" + "</BODY></HTML>"); }
private void requestDispatch( ServletContext ctx, HttpServletRequest req, HttpServletResponse resp, String userID, String page) throws ServletException, IOException { ctx.getRequestDispatcher(page).include(req, resp); }
public void init() { context = getServletContext(); synchronized (context) { pool = (ConnectionPool) context.getAttribute("pool"); if (pool == null) { String driverClassName = context.getInitParameter("driverClassName"); String url = context.getInitParameter("url"); String userName = context.getInitParameter("username"); String password = context.getInitParameter("password"); try { pool = new ConnectionPool(driverClassName, url, userName, password); } catch (Exception error) { Routines.writeToLog( servletName, "Unable to create connection pool : " + error, false, context); } context.setAttribute("pool", pool); } } }
public static void initDebugging(ServletContext webapp) { if (isDebugInit) return; isDebugInit = true; String debugOn = webapp.getInitParameter("DebugOn"); if (debugOn != null) { StringTokenizer toker = new StringTokenizer(debugOn); while (toker.hasMoreTokens()) Debug.set(toker.nextToken(), true); } }
public void init() throws ServletException { ServletContext context = getServletContext(); String driver = context.getInitParameter("p1"); String cs = context.getInitParameter("p2"); String username = context.getInitParameter("p3"); String password = context.getInitParameter("p4"); try { Class.forName(driver); con = DriverManager.getConnection(cs, username, password); ps = con.prepareStatement( "select * from registration1 where username=? and password=? and user_type=?"); } catch (Exception e) { e.printStackTrace(); } }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fn = getServletContext().getRealPath("/WEB-INF/counter.txt"); String strBefore = ""; String strAfter = ""; int counter = 0; Integer n = null; BufferedReader br = null; BufferedWriter bw = null; response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<html><head><title>Sync Test</title></head><body>"); out.println("<h2> Block Synchronized</h2>"); try { synchronized (this) { // カウンターを読む br = new BufferedReader(new FileReader(fn)); strBefore = br.readLine(); br.close(); // カウンターを増やす counter = Integer.parseInt(strBefore); counter++; n = new Integer(counter); strAfter = n.toString(); // カウンターを書き込む bw = new BufferedWriter(new FileWriter(fn)); bw.write(strAfter); bw.close(); } } catch (Exception e) { out.println("エラー:" + e.getMessage() + "<br><pre>"); e.printStackTrace(out); out.println("</pre>"); } out.println("現在のカウント:" + strBefore + "<p>"); out.println("更新後のカウント:" + strAfter + "<p>"); ServletContext context = getServletContext(); String s = (String) context.getAttribute("lastsvl"); out.println("<p>lastsvl: " + s); context.setAttribute("lastsvl", "SynchronizedTest"); out.println("</body></html>"); out.close(); }
private Element getDescription(String task) { if (task != null) { if (task.equals("define")) return definer.getDescription(); if (task.equals("compare")) return comparer.getDescription(); if (task.equals("search")) return searcher.getDescription(); if (task.equals("wikify")) return wikifier.getDescription(); } Element description = doc.createElement("Description"); description.appendChild( createElement( "Details", "<p>This servlet provides a range of services for mining information from Wikipedia. Further details depend on what you want to do.</p>" + "<p>You can <a href=\"" + context.getInitParameter("service_name") + "?task=search&help\">search for pages</a>, <a href=\"" + context.getInitParameter("service_name") + "?task=compare&help\">measure how terms or articles related to each other</a>, <a href=\"" + context.getInitParameter("service_name") + "?task=define&help\">obtain short definitions from articles</a>, and <a href=\"" + context.getInitParameter("service_name") + "?task=wikify&help\">detect topics in web pages</a>.</p>")); Element paramTask = createElement( "Parameter", "Specifies what you want to do: can be <em>search</em>, <em>compare</em>, <em>define</em>, or <em>wikify</em>"); paramTask.setAttribute("name", "task"); description.appendChild(paramTask); Element paramId = doc.createElement("Parameter"); paramId.setAttribute("name", "help"); paramId.appendChild(doc.createTextNode("Specifies that you want help about the service.")); description.appendChild(paramId); return description; }
private void servletEnv() { if (!log.isDebugEnabled()) return; try { java.net.URL url = servletContext.getResource("/"); log.trace("Joseki base directory: " + url); } catch (Exception ex) { } if (servletConfig != null) { String tmp = servletConfig.getServletName(); log.trace("Servlet = " + (tmp != null ? tmp : "<null>")); @SuppressWarnings("unchecked") Enumeration<String> en = servletConfig.getInitParameterNames(); for (; en.hasMoreElements(); ) { String s = en.nextElement(); log.trace("Servlet parameter: " + s + " = " + servletConfig.getInitParameter(s)); } } if (servletContext != null) { // Name of webapp String tmp = servletContext.getServletContextName(); // msg(Level.FINE, "Webapp = " + (tmp != null ? tmp : "<null>")); log.debug("Webapp = " + (tmp != null ? tmp : "<null>")); // NB This servlet may not have been loaded as part of a web app @SuppressWarnings("unchecked") Enumeration<String> en = servletContext.getInitParameterNames(); for (; en.hasMoreElements(); ) { String s = en.nextElement(); log.debug("Webapp parameter: " + s + " = " + servletContext.getInitParameter(s)); } } /* for ( Enumeration enum = servletContext.getAttributeNames() ; enum.hasMoreElements() ; ) { String s = (String)enum.nextElement() ; logger.log(LEVEL, "Webapp attribute: "+s+" = "+context.getAttribute(s)) ; } */ }
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { HttpSession session = req.getSession(false); ServletContext sc = getServletContext(); RequestDispatcher rd; String strPrizeID = req.getParameter("prizeid"); if (strPrizeID != null) { DataBaseConn DelPrizeDBC = new DataBaseConn(); String sqlStr = "delete from pthwinnum where id='" + Integer.parseInt(strPrizeID) + "';"; DelPrizeDBC.execute(sqlStr); DelPrizeDBC.connCloseUpdate(); } PageInfoGet objPageInfoGet = new PageInfoGet(); String strChSql = "select id from pthwinnum"; objPageInfoGet.generInfo(req, "pthwinnum", strChSql); session.setAttribute("userpc", objPageInfoGet.getUserPageConn()); session.setAttribute("bepagshow", objPageInfoGet.getBeanPageShow()); rd = sc.getRequestDispatcher("/WEB-INF/usermanage/pth/pthprizepage.jsp"); rd.forward(req, res); }