/** * Parse the case id from the url and then delete it. Finally redirects the response and the * request to admCase.jsp * * @see DatabaseMethods#caseDelete(int) * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); DatabaseMethods dbPoint = new DatabaseMethods(); HttpSession userSession = request.getSession(); if (Integer.parseInt(userSession.getAttribute("isadmin").toString()) == 1) { int caseId = Integer.parseInt(request.getParameter("caseId")); int success = dbPoint.caseDelete(caseId); if (success != 0) { userSession.setAttribute("caseDelete", "1"); } else { userSession.setAttribute("caseDelete", "0"); } } RequestDispatcher rd = getServletContext().getRequestDispatcher("/admCase.jsp"); if (rd != null) { rd.forward(request, response); } }
// post方式发送email public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); File file = doAttachment(request); EmailAttachment attachment = new EmailAttachment(); attachment.setPath(file.getPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(file.getName()); MultiPartEmail email = new MultiPartEmail(); email.setCharset("UTF-8"); email.setHostName("smtp.sina.com"); email.setAuthentication("T-GWAP", "dangdang"); try { email.addTo(parameters.get("to")); email.setFrom(parameters.get("from")); email.setSubject(parameters.get("subject")); email.setMsg(parameters.get("body")); email.attach(attachment); email.send(); request.setAttribute("sendmail.message", "邮件发送成功!"); } catch (EmailException e) { Logger logger = Logger.getLogger(SendAttachmentMailServlet.class); logger.error("邮件发送不成功", e); request.setAttribute("sendmail.message", "邮件发送不成功!"); } request.getRequestDispatcher("/sendResult.jsp").forward(request, response); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("gb2312"); String delete = request.getParameter("delete"); Login loginBean = null; HttpSession session = request.getSession(true); try { loginBean = (Login) session.getAttribute("loginBean"); boolean b = loginBean.getLogname() == null || loginBean.getLogname().length() == 0; if (b) response.sendRedirect("login.jsp"); // 重定向到登录页面 LinkedList<String> car = loginBean.getCar(); car.remove(delete); } catch (Exception exp) { response.sendRedirect("login.jsp"); // 重定向到登录页面 } RequestDispatcher dispatcher = request.getRequestDispatcher("lookShoppingCar.jsp"); dispatcher.forward(request, response); // 转发 }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // I use "session" in order to throws the object named user bean. HttpSession session = request.getSession(true); response.setContentType("text/html"); request.setCharacterEncoding("UTF-8"); UserBean ub = (UserBean) session.getAttribute("user"); if (ub == null) { String haveLogin = "******"; session.setAttribute("haveLogin", haveLogin); response.sendRedirect("cart"); } else { String mID = ub.getmID(); String iID = (String) request.getParameter("iID"); // String idx = (String)request.getParameter("idx"); Connection conn = null; try { // Getting the connection from database. Class.forName("com.mysql.jdbc.Driver"); /*conn = DriverManager .getConnection("jdbc:mysql://localhost/se?" + "user=root");*/ conn = DriverManager.getConnection( "jdbc:mysql://localhost/user_register?" + "user=sqluser&password=sqluserpw&useUnicode=true&characterEncoding=UTF-8"); String sql = "delete from cart_item_mapping where mID=? and iID = ?"; PreparedStatement pst = conn.prepareStatement(sql); // Using preparedstatement by set the parameter related to "?" symbol. pst.setString(1, mID); pst.setString(2, iID); pst.executeUpdate(); pst.close(); response.sendRedirect("ShowCartController"); } catch (Exception e) { e.printStackTrace(); } } }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(XML_RESPONSE_HEADER); // Talkback happens in XML form. response.setCharacterEncoding("UTF-8"); // Unicode++ request.setCharacterEncoding("UTF-8"); PrintWriter out = null; // The talkback buffer. // handle startrecord Integer startRecord = 0; if (!(request.getParameter("startRecord") == null)) { try { startRecord = Integer.parseInt(request.getParameter("startRecord")) - 1; } catch (NumberFormatException e) { startRecord = 0; } } // maximumrecords Integer maximumRecords = Integer.parseInt(this.config.getProperty("default_maximumRecords")); if (!(request.getParameter("maximumRecords") == null)) { maximumRecords = Integer.parseInt(request.getParameter("maximumRecords")); } // operation String operation = request.getParameter("operation"); // x_collection String x_collection = request.getParameter("x-collection"); if (x_collection == null) x_collection = this.config.getProperty("default_x_collection"); if (x_collection == null) operation = null; // sortkeys String sortKeys = request.getParameter("sortKeys"); // sortorder String sortOrder = request.getParameter("sortOrder"); // recordschema String recordSchema = request.getParameter("recordSchema"); if (recordSchema == null) recordSchema = "dc"; if (recordSchema.equalsIgnoreCase("dcx")) { recordSchema = "dcx"; } if (recordSchema.equalsIgnoreCase("solr")) { recordSchema = "solr"; } // query request String query = request.getParameter("query"); String q = request.getParameter("q"); // who is requestor ? String remote_ip = request.getHeader("X-FORWARDED-FOR"); if (remote_ip == null) { remote_ip = request.getRemoteAddr().trim(); } else { remote_ip = request.getHeader("X-FORWARDED-FOR"); } // handle debug Boolean debug = Boolean.parseBoolean(request.getParameter("debug")); if (!debug) { out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true); } // handle query if ((query == null) && (q != null)) { query = q; } else { if ((query != null) && (q == null)) { q = query; } else { operation = null; } } // handle operation if (operation == null) { if (query != null) { operation = "searchRetrieve"; } else { operation = "explain"; } } // searchRetrieve if (operation.equalsIgnoreCase("searchRetrieve")) { if (query == null) { operation = "explain"; log.debug(operation + ":" + query); } } // start talking back. String[] sq = {""}; String solrquery = ""; // facet String facet = null; List<FacetField> fct = null; if (request.getParameter("facet") != null) { facet = request.getParameter("facet"); log.debug("facet : " + facet); } if (operation == null) { operation = "searchretrieve"; } else { // explain response if (operation.equalsIgnoreCase("explain")) { log.debug("operation = explain"); out.write("<srw:explainResponse xmlns:srw=\"http://www.loc.gov/zing/srw/\">"); out.write("</srw:explainResponse>"); } else { // DEBUG routine operation = "searchretrieve"; String triplequery = null; if (query.matches(".*?\\[.+?\\].*?")) { // New symantic syntax triplequery = symantic_query(query); query = query.split("\\[")[0] + " " + triplequery; log.fatal(triplequery); solrquery = CQLtoLucene.translate(query, log, config); } else { solrquery = CQLtoLucene.translate(query, log, config); } log.debug(solrquery); if (debug == true) { response.setContentType(HTML_RESPONSE_HEADER); out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true); out.write("<html><body>\n\n"); out.write("'" + remote_ip + "'<br>\n"); out.write("<form action='http://www.kbresearch.nl/kbSRU'>"); out.write("<input type=text name=q value='" + query + "' size=120>"); out.write("<input type=hidden name=debug value=True>"); out.write("<input type=submit>"); out.write("<table border=1><tr><td>"); out.write("q</td><td>" + query + "</td></tr><tr>"); out.write("<td>query out</td><td>" + URLDecoder.decode(solrquery) + "</td></tr>"); out.write( "<tr><td>SOLR_URL</td><td> <a href='" + this.config.getProperty( "collection." + x_collection.toLowerCase() + ".solr_baseurl") + "/?q=" + solrquery + "'>" + this.config.getProperty( "collection." + x_collection.toLowerCase() + ".solr_baseurl") + "/select/?q=" + solrquery + "</a><br>" + this.config.getProperty("solr_url") + solrquery + "</td></tr>"); out.write( "<b>SOLR_QUERY</b> : <BR> <iframe width=900 height=400 src='" + this.config.getProperty( "collection." + x_collection.toLowerCase() + ".solr_baseurl") + "/../?q=" + solrquery + "'></iframe><BR>"); out.write( "<b>SRU_QUERY</b> : <BR> <a href=" + this.config.getProperty("baseurl") + "?q=" + query + "'>" + this.config.getProperty("baseurl") + "?q=" + query + "</a><br><iframe width=901 height=400 src='http://www.kbresearch.nl/kbSRU/?q=" + query + "'></iframe><BR>"); out.write( "<br><b>JSRU_QUERY</b> : <BR><a href='http://jsru.kb.nl/sru/?query=" + query + "&x-collection=" + x_collection + "'>http://jsru.kb.nl/sru/?query=" + query + "&x-collection=GGC</a><br><iframe width=900 height=400 src='http://jsru.kb.nl/sru/?query=" + query + "&x-collection=GGC'></iframe>"); } else { // XML SearchRetrieve response String url = this.config.getProperty("collection." + x_collection.toLowerCase() + ".solr_baseurl"); String buffer = ""; CommonsHttpSolrServer server = null; server = new CommonsHttpSolrServer(url); log.fatal("URSING " + url); server.setParser(new XMLResponseParser()); int numfound = 0; try { SolrQuery do_query = new SolrQuery(); do_query.setQuery(solrquery); do_query.setRows(maximumRecords); do_query.setStart(startRecord); if ((sortKeys != null) && (sortKeys.length() > 1)) { if (sortOrder != null) { if (sortOrder.equals("asc")) { do_query.setSortField(sortKeys, SolrQuery.ORDER.asc); } if (sortOrder.equals("desc")) { do_query.setSortField(sortKeys, SolrQuery.ORDER.desc); } } else { for (String str : sortKeys.trim().split(",")) { str = str.trim(); if (str.length() > 1) { if (str.equals("date")) { do_query.setSortField("date_date", SolrQuery.ORDER.desc); log.debug("SORTORDERDEBUG | DATE! " + str + " | "); break; } else { do_query.setSortField(str + "_str", SolrQuery.ORDER.asc); log.debug("SORTORDERDEBUG | " + str + " | "); break; } } } } } if (facet != null) { if (facet.indexOf(",") > 1) { for (String str : facet.split(",")) { if (str.indexOf("date") > 1) { do_query.addFacetField(str); } else { do_query.addFacetField(str); } // do_query.setParam("facet.method", "enum"); } // q.setFacetSort(false); } else { do_query.addFacetField(facet); } do_query.setFacet(true); do_query.setFacetMinCount(1); do_query.setFacetLimit(-1); } log.fatal(solrquery); QueryResponse rsp = null; boolean do_err = false; boolean do_sugg = false; SolrDocumentList sdl = null; String diag = ""; StringBuffer suggest = new StringBuffer(""); String content = "1"; SolrQuery spellq = do_query; try { rsp = server.query(do_query); } catch (SolrServerException e) { String header = this.SRW_HEADER.replaceAll("\\$numberOfRecords", "0"); out.write(header); diag = this.SRW_DIAG.replaceAll("\\$error", e.getMessage()); do_err = true; rsp = null; } log.fatal("query done.."); if (!(do_err)) { // XML dc response SolrDocumentList docs = rsp.getResults(); numfound = (int) docs.getNumFound(); int count = startRecord; String header = this.SRW_HEADER.replaceAll("\\$numberOfRecords", Integer.toString(numfound)); out.write(header); out.write("<srw:records>"); Iterator<SolrDocument> iter = rsp.getResults().iterator(); while (iter.hasNext()) { count += 1; if (recordSchema.equalsIgnoreCase("dc")) { SolrDocument resultDoc = iter.next(); content = (String) resultDoc.getFieldValue("id"); out.write("<srw:record>"); out.write("<srw:recordPacking>xml</srw:recordPacking>"); out.write("<srw:recordSchema>info:srw/schema/1/dc-v1.1</srw:recordSchema>"); out.write( "<srw:recordData xmlns:srw_dc=\"info:srw/schema/1/dc-v1.1\" xmlns:mods=\"http://www.loc.gov/mods\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dcx=\"http://krait.kb.nl/coop/tel/handbook/telterms.html\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:marcrel=\"http://www.loc.gov/loc.terms/relators/OTH\" xmlns:facets=\"info:srw/extension/4/facets\" >"); StringBuffer result = new StringBuffer(""); construct_lucene_dc(result, resultDoc); out.write(result.toString()); out.write("</srw:recordData>"); out.write( "<srw:recordPosition>" + Integer.toString(count) + "</srw:recordPosition>"); out.write("</srw:record>"); } if (recordSchema.equalsIgnoreCase("solr")) { SolrDocument resultDoc = iter.next(); content = (String) resultDoc.getFieldValue("id"); out.write("<srw:record>"); out.write("<srw:recordPacking>xml</srw:recordPacking>"); out.write("<srw:recordSchema>info:srw/schema/1/solr</srw:recordSchema>"); out.write("<srw:recordData xmlns:expand=\"http://www.kbresearch.nl/expand\">"); StringBuffer result = new StringBuffer(""); construct_lucene_solr(result, resultDoc); out.write(result.toString()); out.write("</srw:recordData>"); out.write( "<srw:recordPosition>" + Integer.toString(count) + "</srw:recordPosition>"); out.write("</srw:record>"); } if (recordSchema.equalsIgnoreCase("dcx")) { // XML dcx response out.write("<srw:record>"); out.write("<srw:recordPacking>xml</srw:recordPacking>"); out.write("<srw:recordSchema>info:srw/schema/1/dc-v1.1</srw:recordSchema>"); out.write( "<srw:recordData><srw_dc:dc xmlns:srw_dc=\"info:srw/schema/1/dc-v1.1\" xmlns:mods=\"http://www.loc.gov/mods\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dcx=\"http://krait.kb.nl/coop/tel/handbook/telterms.html\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:marcrel=\"http://www.loc.gov/marc.relators/\" xmlns:expand=\"http://www.kbresearch.nl/expand\" xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" >"); SolrDocument resultDoc = iter.next(); content = (String) resultDoc.getFieldValue("id"); String dcx_data = helpers.getOAIdcx( "http://services.kb.nl/mdo/oai?verb=GetRecord&identifier=" + content, log); if (x_collection.equalsIgnoreCase("ggc-thes")) { dcx_data = helpers.getOAIdcx( "http://serviceso.kb.nl/mdo/oai?verb=GetRecord&identifier=" + content, log); } if (!(dcx_data.length() == 0)) { out.write(dcx_data); } else { // Should not do this!! out.write("<srw:record>"); out.write("<srw:recordPacking>xml</srw:recordPacking>"); out.write("<srw:recordSchema>info:srw/schema/1/dc-v1.1</srw:recordSchema>"); out.write( "<srw:recordData xmlns:srw_dc=\"info:srw/schema/1/dc-v1.1\" xmlns:mods=\"http://www.loc.gov/mods\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dcx=\"http://krait.kb.nl/coop/tel/handbook/telterms.html\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:marcrel=\"http://www.loc.gov/loc.terms/relators/OTH\" >"); StringBuffer result = new StringBuffer(""); construct_lucene_dc(result, resultDoc); out.write(result.toString()); out.write("</srw:recordData>"); out.write( "<srw:recordPosition>" + Integer.toString(count) + "</srw:recordPosition>"); out.write("</srw:record>"); } out.write("</srw_dc:dc>"); StringBuffer expand_data; boolean expand = false; if (content.startsWith("GGC-THES:AC:")) { String tmp_content = ""; tmp_content = content.replaceFirst("GGC-THES:AC:", ""); log.fatal("calling get"); expand_data = new StringBuffer( helpers.getExpand( "http://www.kbresearch.nl/general/lod_new/get/" + tmp_content + "?format=rdf", log)); log.fatal("get finini"); if (expand_data.toString().length() > 4) { out.write( "<srw_dc:expand xmlns:srw_dc=\"info:srw/schema/1/dc-v1.1\" xmlns:expand=\"http://www.kbresearch.nl/expand\" xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" >"); out.write(expand_data.toString()); expand = true; } } else { expand_data = new StringBuffer( helpers.getExpand( "http://www.kbresearch.nl/ANP.cgi?q=" + content, log)); if (expand_data.toString().length() > 0) { if (!expand) { out.write( "<srw_dc:expand xmlns:srw_dc=\"info:srw/schema/1/dc-v1.1\" xmlns:expand=\"http://www.kbresearch.nl/expand\" xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" >"); expand = true; } out.write(expand_data.toString()); } } if (expand) { out.write("</srw_dc:expand>"); } out.write("</srw:recordData>"); out.write( "<srw:recordPosition>" + Integer.toString(count) + "</srw:recordPosition>"); out.write("</srw:record>"); } } } if ((do_err) || (numfound == 0)) { log.fatal("I haz suggestions"); try { spellq.setParam("spellcheck", true); spellq.setQueryType("/spell"); server = new CommonsHttpSolrServer(url); rsp = server.query(spellq); sdl = rsp.getResults(); SpellCheckResponse spell; spell = rsp.getSpellCheckResponse(); List<SpellCheckResponse.Suggestion> suggestions = spell.getSuggestions(); if (suggestions.isEmpty() == false) { suggest.append("<srw:extraResponseData>"); suggest.append("<suggestions>"); for (SpellCheckResponse.Suggestion sugg : suggestions) { suggest.append("<suggestionfor>" + sugg.getToken() + "</suggestionfor>"); for (String item : sugg.getSuggestions()) { suggest.append("<suggestion>" + item + "</suggestion>"); } suggest.append("</suggestions>"); suggest.append("</srw:extraResponseData>"); } do_sugg = true; } } catch (Exception e) { rsp = null; // log.fatal(e.toString()); } ; } ; if (!do_err) { if (facet != null) { try { fct = rsp.getFacetFields(); out.write("<srw:facets>"); for (String str : facet.split(",")) { out.write("<srw:facet>"); out.write("<srw:facetType>"); out.write(str); out.write("</srw:facetType>"); for (FacetField f : fct) { log.debug(f.getName()); // if (f.getName().equals(str+"_str") || (f.getName().equals(str+"_date")) ) { List<FacetField.Count> facetEnties = f.getValues(); for (FacetField.Count fcount : facetEnties) { out.write("<srw:facetValue>"); out.write("<srw:valueString>"); out.write(helpers.xmlEncode(fcount.getName())); out.write("</srw:valueString>"); out.write("<srw:count>"); out.write(Double.toString(fcount.getCount())); out.write("</srw:count>"); out.write("</srw:facetValue>"); // } } } out.write("</srw:facet>"); } out.write("</srw:facets>"); startRecord += 1; } catch (Exception e) { } // log.fatal(e.toString()); } } } else { out.write(diag); } out.write("</srw:records>"); // SearchRetrieve response footer String footer = this.SRW_FOOTER.replaceAll("\\$query", helpers.xmlEncode(query)); footer = footer.replaceAll("\\$startRecord", (startRecord).toString()); footer = footer.replaceAll("\\$maximumRecords", maximumRecords.toString()); footer = footer.replaceAll("\\$recordSchema", recordSchema); if (do_sugg) { out.write(suggest.toString()); } out.write(footer); } catch (MalformedURLException e) { out.write(e.getMessage()); } catch (IOException e) { out.write("TO ERR is Human"); } } } } out.close(); }
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'); request.setCharacterEncoding("UTF-8"); boolean isRTL = UrlUtil.isRTL(request, response); String direction = isRTL ? "rtl" : "ltr"; if (new RequestData(application, request, response).isMozilla()) { out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n"); } else { out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"); } out.write( "<!------------------------------------------------------------------------------\n"); out.write(" ! Copyright (c) 2000, 2007 IBM Corporation and others.\n"); out.write(" ! All rights reserved. This program and the accompanying materials \n"); out.write(" ! are made available under the terms of the Eclipse Public License v1.0\n"); out.write(" ! which accompanies this distribution, and is available at\n"); out.write(" ! http://www.eclipse.org/legal/epl-v10.html\n"); out.write(" ! \n"); out.write(" ! Contributors:\n"); out.write(" ! IBM Corporation - initial API and implementation\n"); out.write( " ------------------------------------------------------------------------------->"); out.write('\n'); out.write('\n'); SearchData data = new SearchData(application, request, response); WebappPreferences prefs = data.getPrefs(); out.write("\n"); out.write("\n"); out.write("\n"); out.write("<html lang=\""); out.print(ServletResources.getString("locale", request)); out.write("\">\n"); out.write("<head>\n"); out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); out.write("\n"); out.write("<title>"); out.print(ServletResources.getString("SearchLabel", request)); out.write("</title>\n"); out.write(" \n"); out.write("<style type=\"text/css\">\n"); out.write("/* need this one for Mozilla */\n"); out.write("HTML { \n"); out.write("\twidth:100%;\n"); out.write("\theight:100%;\n"); out.write("\tmargin:0px;\n"); out.write("\tpadding:0px;\n"); out.write("\tborder:0px;\n"); out.write(" }\n"); out.write("\n"); out.write("BODY {\n"); out.write("\tbackground:"); out.print(prefs.getToolbarBackground()); out.write(";\n"); out.write("\tborder:0px;\n"); out.write("\theight:100%;\n"); out.write("}\n"); out.write("\n"); out.write("TABLE {\n"); out.write("\tfont: "); out.print(prefs.getToolbarFont()); out.write(";\n"); out.write("\tbackground:"); out.print(prefs.getToolbarBackground()); out.write(";\n"); out.write("\tmargin: 0px;\n"); out.write("\tpadding: 0px;\n"); out.write("\theight:100%;\n"); out.write("}\n"); out.write("\n"); out.write("FORM {\n"); out.write("\tbackground:"); out.print(prefs.getToolbarBackground()); out.write(";\n"); out.write("\theight:100%;\n"); out.write("\tmargin:0px;\n"); out.write("}\n"); out.write("\n"); out.write("INPUT {\n"); out.write("\tfont: "); out.print(prefs.getToolbarFont()); out.write(";\n"); out.write("\tmargin:0px;\n"); out.write("\tpadding:0px;\n"); out.write("}\n"); out.write("\n"); out.write("INPUT {\n"); out.write(" font-size: 1.0em;\n"); out.write("}\n"); out.write("\n"); out.write("A {\n"); out.write("\tcolor:WindowText;\n"); out.write("\ttext-decoration:none;\n"); out.write("}\n"); out.write("\n"); out.write("#searchTD {\n"); out.write("\tpadding-"); out.print(isRTL ? "right" : "left"); out.write(":7px;\n"); out.write("\tpadding-"); out.print(isRTL ? "left" : "right"); out.write(":4px;\n"); out.write("}\n"); out.write("\n"); out.write("#searchWord {\n"); out.write("\tmargin-left:5px;\n"); out.write("\tmargin-right:5px;\n"); out.write("\tborder:1px solid ThreeDShadow;\n"); out.write("}\n"); out.write("\n"); out.write("#searchLabel {\n"); out.write("\tcolor:WindowText;\n"); out.write("}\n"); out.write("\n"); out.write("#go {\n"); if (data.isMacMozilla()) { out.write("\n"); out.write(" background:GrayText;\n"); } else { out.write("\n"); out.write(" background:ThreeDShadow;\n"); } out.write("\n"); out.write("\tcolor:Window;\n"); out.write("\tfont-weight:bold;\n"); out.write("\tborder:1px solid ThreeDShadow;\n"); out.write("\tmargin-left:1px;\n"); out.write("\tfont-size: 1.0em;\n"); out.write("}\n"); out.write("\n"); out.write("#scopeLabel {\n"); out.write("\ttext-decoration:underline; \n"); out.write("\tcolor:#0066FF; \n"); out.write("\tcursor:pointer;\n"); out.write("\tpadding-left:15px; /* This should be the same for both RTL and LTR. */\n"); out.write("}\n"); out.write("\n"); out.write("#scope { \n"); out.write("\ttext-align:"); out.print(isRTL ? "left" : "right"); out.write(";\n"); out.write("\tmargin-"); out.print(isRTL ? "right" : "left"); out.write(":5px;\n"); out.write("\tborder:0px;\n"); out.write("\tcolor:WindowText;\n"); out.write("\ttext-decoration:none;\n"); out.write("}\n"); out.write("\n"); if (data.isIE()) { out.write("\n"); out.write("#go {\n"); out.write("\tpadding-"); out.print(isRTL ? "right" : "left"); out.write(":1px;\n"); out.write("}\n"); } out.write("\n"); out.write("</style>\n"); out.write("\n"); out.write("<script language=\"JavaScript\">\n"); out.write("var isIE = navigator.userAgent.indexOf('MSIE') != -1;\n"); out.write( "var isMozilla = navigator.userAgent.toLowerCase().indexOf('mozilla') != -1 && parseInt(navigator.appVersion.substring(0,1)) >= 5;\n"); out.write("\n"); out.write("var advancedDialog;\n"); out.write("\n"); out.write("function openAdvanced() \n"); out.write("{ \n"); out.write(" var scope = document.getElementById(\"scope\").firstChild;\n"); out.write(" var workingSet = \"\"; \n"); out.write(" if (scope != null) \n"); out.write( " workingSet = document.getElementById(\"scope\").firstChild.nodeValue; \n"); out.write(" var minSize = 300; \n"); out.write(" var maxHeight= 500; \n"); out.write(" var maxWidth = 600; \n"); out.write(" var w = minSize; \n"); out.write(" var h = minSize; \n"); out.write(" \n"); out.write( " // If we have large fonts make the dialog larger, up to 500 pixels high, 600 wide\n"); out.write(" try { \n"); out.write( " var letterHeight = document.getElementById(\"searchWord\").offsetHeight; \n"); out.write(" var requiredSize = 16 * letterHeight; \n"); out.write(" if (requiredSize > minSize) { \n"); out.write(" if (requiredSize < maxWidth) { \n"); out.write(" w = requiredSize; \n"); out.write(" } else { \n"); out.write(" w = maxWidth; \n"); out.write(" }\n"); out.write(" if (requiredSize < maxHeight) { \n"); out.write(" h = requiredSize; \n"); out.write(" } else { \n"); out.write(" h = maxHeight;\n"); out.write(" }\n"); out.write(" } \n"); out.write(" \n"); out.write(" } catch (e) {} \n"); out.write(" \n"); if (data.isIE()) { out.write("\n"); out.write("\tvar l = parent.screenLeft + (parent.document.body.clientWidth - w) / 2;\n"); out.write("\tvar t = parent.screenTop + (parent.document.body.clientHeight - h) / 2;\n"); } else { out.write("\n"); out.write("\tvar l = parent.screenX + (parent.innerWidth - w) / 2;\n"); out.write("\tvar t = parent.screenY + (parent.innerHeight - h) / 2;\n"); } out.write("\n"); out.write("\t// move the dialog just a bit higher than the middle\n"); out.write("\tif (t-50 > 0) t = t-50;\n"); out.write("\t\n"); out.write("\twindow.location=\"javascript://needModal\";\n"); out.write( "\tadvancedDialog = window.open(\"workingSetManager.jsp?workingSet=\"+encodeURIComponent(workingSet), \"advancedDialog\", \"resizable=yes,height=\"+h+\",width=\"+w+\",left=\"+l+\",top=\"+t );\n"); out.write("\tadvancedDialog.focus(); \n"); out.write("}\n"); out.write("\n"); out.write("function closeAdvanced()\n"); out.write("{\n"); out.write("\ttry {\n"); out.write("\t\tif (advancedDialog)\n"); out.write("\t\t\tadvancedDialog.close();\n"); out.write("\t}\n"); out.write("\tcatch(e) {}\n"); out.write("}\n"); out.write("\n"); out.write("/**\n"); out.write(" * This function can be called from this page or from\n"); out.write(" * the advanced search page. When called from the advanced\n"); out.write(" * search page, a query is passed.\n"); out.write(" * noRefocus is a boolean which if true suppresses\n"); out.write(" * switch of focus to the search view\n"); out.write(" */\n"); out.write("function doSearch(query, noRefocus)\n"); out.write("{\n"); out.write("\tvar workingSet = document.getElementById(\"scope\").firstChild.nodeValue;\n"); out.write("\n"); out.write("\tvar form = document.forms[\"searchForm\"];\n"); out.write("\tvar searchWord = form.searchWord.value;\n"); out.write("\tvar maxHits = form.maxHits.value;\n"); out.write("\tif (!searchWord || searchWord == \"\")\n"); out.write("\t\treturn;\n"); out.write("\tquery =\"searchWord=\"+encodeURIComponent(searchWord)+\"&maxHits=\"+maxHits;\n"); out.write("\tif (workingSet != '"); out.print(UrlUtil.JavaScriptEncode(ServletResources.getString("All", request))); out.write("')\n"); out.write("\t\tquery = query +\"&scope=\"+encodeURIComponent(workingSet);\n"); out.write("\t\t\n"); out.write("\t/******** HARD CODED VIEW NAME *********/\n"); out.write("\t// do some tests to ensure the results are available\n"); out.write("\tif (parent.parent.HelpFrame && \n"); out.write("\t\tparent.parent.HelpFrame.NavFrame && \n"); out.write("\t\tparent.parent.HelpFrame.NavFrame.showView &&\n"); out.write("\t\tparent.parent.HelpFrame.NavFrame.ViewsFrame && \n"); out.write("\t\tparent.parent.HelpFrame.NavFrame.ViewsFrame.search && \n"); out.write("\t\tparent.parent.HelpFrame.NavFrame.ViewsFrame.search.searchViewFrame) \n"); out.write("\t{\n"); out.write("\t if (!noRefocus) {\n"); out.write("\t\t parent.parent.HelpFrame.NavFrame.showView(\"search\");\n"); out.write("\t\t}\n"); out.write( "\t\tvar searchView = parent.parent.HelpFrame.NavFrame.ViewsFrame.search.searchViewFrame;\n"); out.write("\t\tsearchView.location.replace(\"searchView.jsp?\"+query);\n"); out.write("\t}\n"); out.write("}\n"); out.write("\n"); out.write("function getSearchWord() {\n"); out.write(" var form = document.forms[\"searchForm\"];\n"); out.write(" var searchWord = form.searchWord.value;\n"); out.write(" if (searchWord ) {\n"); out.write(" return searchWord;\n"); out.write(" }\n"); out.write(" return \"\";\n"); out.write("}\n"); out.write("\n"); out.write("function rescope() {\n"); out.write(" if (parent.parent.HelpFrame && \n"); out.write("\t\tparent.parent.HelpFrame.NavFrame && \n"); out.write("\t\tparent.parent.HelpFrame.NavFrame.ViewsFrame) {\n"); out.write("\t\tvar viewsFrame = parent.parent.HelpFrame.NavFrame.ViewsFrame;\n"); out.write("\t\tif (viewsFrame.toc && viewsFrame.toc.tocViewFrame) {\n"); out.write("\t\t var tocView = viewsFrame.toc.tocViewFrame;\n"); out.write("\t\t tocView.repaint();\n"); out.write("\t\t}\n"); out.write("\t\tif (viewsFrame.index && viewsFrame.index.indexViewFrame) {\n"); out.write("\t\t var indexView = viewsFrame.index.indexViewFrame;\n"); out.write("\t\t indexView.repaint();\n"); out.write("\t\t}\n"); out.write("\t\tdoSearch(null, true);\n"); out.write("\t}\n"); out.write("}\n"); out.write("\n"); out.write("function fixHeights()\n"); out.write("{\n"); out.write("\tif (!isIE) return;\n"); out.write("\t\n"); out.write("\tvar h = document.getElementById(\"searchWord\").offsetHeight;\n"); out.write("\tdocument.getElementById(\"go\").style.height = h;\n"); out.write("}\n"); out.write("\n"); out.write("function onloadHandler(e)\n"); out.write("{\n"); out.write("\tvar form = document.forms[\"searchForm\"];\n"); out.write("\tform.searchWord.value = '"); out.print(UrlUtil.JavaScriptEncode(data.getSearchWord())); out.write("';\n"); out.write("\tfixHeights();\n"); if (data.isScopeRequest() && RequestScope.filterBySearchScope(request)) { out.write("\n"); out.write(" rescope();\n"); } out.write("\n"); out.write("}\n"); out.write("\n"); out.write("</script>\n"); out.write("\n"); out.write("</head>\n"); out.write("\n"); out.write("<body dir=\""); out.print(direction); out.write("\" onload=\"onloadHandler()\" onunload=\"closeAdvanced()\">\n"); out.write("\n"); out.write("\t<form name=\"searchForm\" onsubmit=\"doSearch()\">\n"); out.write("\t<div role=\"search\">\n"); out.write("\t\t<table id=\"searchTable\" align=\""); out.print(isRTL ? "right" : "left"); out.write( "\" valign=\"middle\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" role=\"presentation\">\n"); out.write("\t\t\t<tr nowrap valign=\"middle\">\n"); out.write("\t\t\t\t<td "); out.print(isRTL ? "nowrap" : ""); out.write(" id=\"searchTD\">\n"); out.write("\t\t\t\t\t<label id=\"searchLabel\" for=\"searchWord\" accesskey=\""); out.print(ServletResources.getAccessKey("SearchLabel", request)); out.write("\">\n"); out.write("\t\t\t\t\t "); out.print(ServletResources.getLabel("SearchLabel", request)); out.write("\n"); out.write("\t\t\t\t\t</label>\n"); out.write("\t\t\t\t</td>\n"); out.write("\t\t\t\t<td>\n"); out.write( "\t\t\t\t\t<input type=\"text\" id=\"searchWord\" name=\"searchWord\" value='' size=\"24\" maxlength=\"256\" \n"); out.write("\t\t\t\t\t alt=\""); out.print(UrlUtil.htmlEncode(ServletResources.getString("expression_label", request))); out.write("\" \n"); out.write("\t\t\t\t\t title=\""); out.print(UrlUtil.htmlEncode(ServletResources.getString("expression_label", request))); out.write("\">\n"); out.write("\t\t\t\t</td>\n"); out.write("\t\t\t\t<td >\n"); out.write( "\t\t\t\t\t<input type=\"submit\" role=\"button\" onclick=\"this.blur();doSearch()\" value=\""); out.print(ServletResources.getString("GO", request)); out.write("\" id=\"go\" alt=\""); out.print(ServletResources.getString("GO", request)); out.write("\" title=\""); out.print(ServletResources.getString("GO", request)); out.write("\">\n"); out.write("\t\t\t\t\t<input type=\"hidden\" name=\"maxHits\" value=\"500\" >\n"); out.write("\t\t\t\t</td>\n"); out.write("\t\t\t\t<td nowrap>\n"); out.write("\t\t\t\t\t<a id=\"scopeLabel\" href=\"javascript:openAdvanced();\" title=\""); out.print(ServletResources.getString("ScopeTooltip", request)); out.write("\" alt=\""); out.print(ServletResources.getString("ScopeTooltip", request)); out.write("\" onmouseover=\"window.status='"); out.print(UrlUtil.JavaScriptEncode(ServletResources.getString("ScopeTooltip", request))); out.write("'; return true;\" onmouseout=\"window.status='';\">"); out.print(ServletResources.getLabel("Scope", request)); out.write("</a>\n"); out.write("\t\t\t\t</td>\n"); out.write("\t\t\t\t<td nowrap>\n"); out.write("\t\t\t\t\t<input type=\"hidden\" name=\"workingSet\" value='"); out.print(UrlUtil.htmlEncode(data.getScope())); out.write("'>\n"); out.write("\t\t\t\t\t<div id=\"scope\" >"); out.print(UrlUtil.htmlEncode(data.getScope())); out.write("</div>\n"); out.write("\t\t\t\t</td>\n"); out.write("\t\t\t</tr>\n"); out.write("\n"); out.write("\t\t</table>\n"); out.write("\t</div>\n"); out.write("\t</form>\t\t\n"); out.write("\n"); out.write("</body>\n"); out.write("</html>\n"); 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); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("utf-8"); if (jjNumber.isDigit(jjTools.getParameter(request, "maxSize"))) { maxSize = Long.parseLong(jjTools.getParameter(request, "maxSize")); } response.setCharacterEncoding("utf-8"); String name = request.getParameter("name"); name = name == null ? "" : name; response.setContentType("text/plain"); super.init(getServletConfig()); // response.setContentType("text/plain"); PrintWriter out = response.getWriter(); // out.println(); DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(); // fileItemFactory.setSizeThreshold(1024 * 1024); //1 MB try { ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory); List items = uploadHandler.parseRequest(request); Iterator itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if (item.isFormField()) { /* * Field */ // out.println("Field Name=" + item.getFieldName() + ", Value=" + // item.getString()); data.put(item.getFieldName(), item.getString()); } else { /* * File */ File folderAddress = new File(request.getServletContext().getRealPath(Save_Folder_Name)); // "/" + String extension = ""; String nameWithoutExtension = item.getName(); if (item.getName().lastIndexOf(".") > -1) { extension = item.getName().substring(item.getName().lastIndexOf(".")); nameWithoutExtension = item.getName() .substring( item.getName().lastIndexOf("\\") + 1, item.getName().lastIndexOf(".")); } folderAddress.mkdirs(); nameWithoutExtension = "P"; File file = new File( folderAddress + "/" + nameWithoutExtension.toLowerCase() + jjNumber.getRandom(10) + extension.toLowerCase()); String i = "0000000000"; while (file.exists()) { i = jjNumber.getRandom(10); file = new File( folderAddress + "/" + nameWithoutExtension.toLowerCase() + i + extension.toLowerCase()); } if (!name.equals("")) { file = new File(folderAddress + "/" + name); } // out.println("File Name=" + item.getName() // + ", Field Name=" + item.getFieldName() // + ", Content type=" + item.getContentType() // + ", File Size=" + item.getSize() // + ", Save Address=" + file); // out.println(file); // String urlPath = // request.getRequestURL().toString().replace("Upload2", "Upload") + "/" + // file.getName().replace("\\", "/"); // out.println("<html><head><meta http-equiv='Content-Type' // content='text/html; charset=utf-8'></head><body><input type='text' name='T1' size='58' // value='" + urlPath + "'></body></html>"); data.put(item.getFieldName(), file.getAbsolutePath()); if (!file.getName().toLowerCase().endsWith(".exe")) { item.write(file); } long size = file.length(); ServerLog.Print("?>>>>>>" + file + " - Size:" + size); if (size > maxSize) { file.delete(); out.print("big"); } else { out.print( file.getName() .replace(" ", "%20") .replace("<pre style=\"word-wrap: break-word; white-space: pre-wrap;\">", "")); ServerLog.Print("Write pic in: " + file + " size:" + file.length()); String name2 = file.getName().substring(0, file.getName().lastIndexOf(".")); String extension2 = file.getName() .substring(file.getName().lastIndexOf(".") + 1, file.getName().length()); File file2 = new File(file.getParent() + "/" + name2 + "_small." + extension2); if (extension2.toLowerCase().equals("jpg") || extension2.toLowerCase().equals("png") || extension2.toLowerCase().equals("gif")) { jjPicture.doChangeSizeOfPic(file, file2, 250); } } } } } catch (Exception ex) { Server.ErrorHandler(ex); } out.flush(); out.close(); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("gb2312"); response.setContentType("text/html; charset=gb2312"); out = response.getWriter(); session = request.getSession(); time = new Time(); str = new Str(); db = new Db(); // 取得 try { id = Integer.parseInt((String) request.getParameter("id")); } catch (Exception e) { id = 0; } password = request.getParameter("password"); password = str.inStr(password); sqlsp = "SELECT * FROM password WHERE employeeid=" + id; sqlse = "SELECT employeeid FROM eminfo WHERE employeeid=" + id; sqlu = "UPDATE password SET time='" + time.getYMDHMS() + "',password='******' WHERE employeeid=" + id; sqli = "INSERT INTO password(employeeid,password,time) VALUES(" + id + ",'" + password + "','" + time.getYMDHMS() + "')"; try { stmt = db.getStmtread(); rs = stmt.executeQuery(sqlsp); // 不是第一次设置更新数据库 if (rs.next()) { db.close(); stmt = db.getStmt(); temp = 0; temp = stmt.executeUpdate(sqlu); if (temp > 0) { request.setAttribute("msg", "设置成功"); } else { request.setAttribute("msg", "设置失败"); } db.close(); } else { // 第一次设置 db.close(); temp = 0; stmt = db.getStmtread(); rs = stmt.executeQuery(sqlse); if (rs.next()) { // id存在 rs.close(); stmt.close(); temp = 0; stmt = db.getStmt(); temp = stmt.executeUpdate(sqli); if (temp > 0) { request.setAttribute("msg", "设置成功"); } else { request.setAttribute("msg", "设置失败"); } db.close(); } else { // id不存在 db.close(); request.setAttribute("msg", "员工序号不存在"); } } } catch (SQLException e) { e.printStackTrace(); } finally { RequestDispatcher dispatcher = request.getRequestDispatcher("set1.jsp"); dispatcher.forward(request, response); } }
public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException { request.setCharacterEncoding(encoding); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!runFlag) { refreshCount++; System.out.println("Refresh " + refreshCount + " times......"); // redirect to index.jsp request.getRequestDispatcher("/index.jsp").forward(request, response); return; } // response.setContentType("text/html;charset=GBK"); request.setCharacterEncoding("GBK"); // PrintWriter out = response.getWriter(); // get global parameters from web projectName = request.getParameter("projectName"); serverIp = request.getParameter("serverIp"); startServerCmd = request.getParameter("startServerCmd"); System.out.println("get projectName from web: " + projectName); System.out.println("get serverIp from web: " + serverIp); System.out.println("get startServerCmd from web: " + startServerCmd); // get stress parameters from web startStressCmd = request.getParameter("startStressCmd"); stressLog = request.getParameter("stressLog"); stressName = request.getParameter("stressName"); System.out.println("get startStressCmd from web: " + startStressCmd); System.out.println("get stressName from web: " + stressName); // get stress IP from web String[] clients = request.getParameterValues("client"); int clientsLen = clients.length; System.out.println("get clients count from web: " + clientsLen); if (clientsLen != 0) { for (String client : clients) { System.out.println("get client from web: " + client); // change projectName in client.config sc.modifyConfigFile(client, clientConfig, PROJECT_NAME, projectName); sc.modifyConfigFile(client, clientConfig, MONITOR_PROCESS, stressName); sc.modifyConfigFile(client, clientConfig, MONITOR_LOG, stressLog); } } else { System.err.println("get no client!!!"); return; } // start servers System.out.println("start servers......"); String startServerRet = (String) (sc.executeCmd(serverIp, startServerCmd, String.class)); System.out.println(startServerRet); sc.waitto(15); // start stress System.out.println("start stress......"); for (String client : clients) { System.out.println("start stress on " + client + "......"); String startStressRet = (String) (sc.executeCmd(client, startStressCmd, String.class)); System.out.println("result: " + startStressRet); } sc.waitto(15); // start clients for (String client : clients) { System.out.println("start client on " + client + "......"); sc.executeCmd(client, startClientCmd); } // redirect to index.jsp request.getRequestDispatcher("/index.jsp").forward(request, response); runFlag = false; // String cmd = "cd /home/admin/ashu/ycsb && ./run.sh workload put @";\ // if (ret1 != null && ret2 != null && ret3 != null) { // out.println("get host by staf: " + ret1); // out.println("<br>"); // out.println("get host by staf: " + ret2); // out.println("<br>"); // out.println("get host by staf: " + ret3); // out.println("<br>"); // } // out.close(); // Enumeration paramNames = request.getParameterNames(); // while (paramNames.hasMoreElements()) { // String paramName = (String) paramNames.nextElement(); // out.print("<TR><TD>" + paramName + "<TD>"); // out.println("<BR>");//print new line // String[] paramValues = request.getParameterValues(paramName); // if (paramValues.length == 1) { // String paramValue = paramValues[0]; // if (paramValue.length() == 0) // out.println("<I>No Value</I>"); // else // out.println(paramValue); // } else { // out.println("<UL>"); // for (int i = 0; i < paramValues.length; i++) { // out.println("<LI>" + paramValues[i]); // } // out.println("</UL>"); // } // } }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // 权限判断 StringBuffer sb = new StringBuffer(); String actionType = null; String queryString = null; String userid = null; String isCanAccess = "1"; HttpServletRequest hrequest = (HttpServletRequest) request; String strContext = hrequest.getContextPath(); if (request instanceof HttpServletRequest) { // 获取用户信息 userid = (String) hrequest.getSession().getAttribute("AuthorizedUserID"); strContext = hrequest.getContextPath(); queryString = hrequest.getQueryString(); // 整个参数串 actionType = hrequest.getParameter("actionType"); // 一般操作 if (actionType == null) { actionType = hrequest.getParameter("formSN"); // 针对查询的操作 if (actionType != null) { actionType = "formSN=" + actionType; } } else { actionType = "actionType=" + actionType; } } if (actionType != null) { // 如果参数不为空,则判断权限,通过存储过程判断 DBConnectionManager dbManager = new DBConnectionManager(); CallableStatement cstmt = null; Connection conn = null; try { conn = dbManager.getConnection(); String query = "{call pkg_security.userAccessFunction(?,?,?,?)}"; cstmt = conn.prepareCall(query); cstmt.registerOutParameter(1, OracleTypes.VARCHAR); cstmt.setString(2, userid); cstmt.setString(3, actionType == null ? null : actionType.trim()); cstmt.setString(4, queryString == null ? null : queryString.trim()); cstmt.execute(); isCanAccess = cstmt.getString(1); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { if (conn != null) try { conn.close(); } catch (SQLException e1) { e1.printStackTrace(); } } if (conn != null) try { conn.close(); } catch (SQLException e1) { e1.printStackTrace(); } } } // 如果没有权限,定位到提示页面。 if (!isCanAccess.equals("1")) { HttpServletResponse out = (HttpServletResponse) response; out.sendRedirect(strContext + "/common/erroraccess.jsp"); return; } else { // 汉字问题 HttpServletRequest httpRequest = (HttpServletRequest) request; httpRequest.setCharacterEncoding(encoding); // chain.doFilter(request, response); // 压缩传输 HttpServletResponse httpResponse = (HttpServletResponse) response; String uri = httpRequest.getRequestURI(); String transferEncoding = getGZIPEncoding((HttpServletRequest) request); if (transferEncoding == null) { setResponseHeader(httpResponse, uri, transferEncoding); chain.doFilter(request, response); } else { if (!uri.endsWith("dd.xml")) // 不处理的有哪些?????? { chain.doFilter(request, response); } else { System.out.println("FrameworkFilter:: Filter handle dd.xml"); setResponseHeader(httpResponse, uri, transferEncoding); httpResponse.setHeader("Content-Encoding", transferEncoding); GZIPEncodableResponse wrappedResponse = new GZIPEncodableResponse((HttpServletResponse) response); chain.doFilter(request, wrappedResponse); wrappedResponse.flush(); } } } // Pass control on to the next filter // chain.doFilter(request, response); }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); HttpSession session = request.getSession(true); // ��� �������� ������� ������ ������������� ����� true request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String phoneToDelete = request.getParameter("phoneToDelete"); String currentName = request.getParameter("name"); // �������� ������ String newPrice = request.getParameter("finPrice"); // �������� ���� ������ String number = request.getParameter("number"); // ���������� ������ String phonesRequestLine = (String) session.getAttribute("phonesRequestLine"); StringTokenizer tok = null; iPhonePageBean[] iPhones = (iPhonePageBean[]) session.getAttribute("iPhones"); int summary = 0; // �������� ���� ������� boolean isNew = true; if (phonesRequestLine != null) { phonesRequestLine = rebuildStringWithException(phonesRequestLine, "null"); tok = new StringTokenizer(phonesRequestLine); } if (currentName != null && newPrice != null && number != null) if (isNumber(Integer.parseInt(number)) && isNumber(Integer.parseInt(newPrice))) { for (int i = 0; i < iPhones.length; ++i) if (iPhones[i].getName().equals(currentName)) { iPhones[i].setNumber(number); iPhones[i].setFinalPrice(newPrice); break; } } for (int i = 0; i < iPhones.length; ++i) if (!iPhones[i].getNumber().equals("0")) { isNew = false; break; } if (isNew) { while (tok.hasMoreElements()) { String temp = tok.nextToken(); for (int i = 0; i < iPhones.length; ++i) if (iPhones[i].getName().equals(temp)) { iPhones[i].setNumber("1"); summary += iPhones[i].getPrice(); } } } else { for (int i = 0; i < iPhones.length; ++i) { summary += (Integer.parseInt(iPhones[i].getNumber()) * iPhones[i].getPrice()); } } //////////////////////////////////////////////////////////////////////// if (phoneToDelete != null && phonesRequestLine != null) { phonesRequestLine = rebuildStringWithException(phonesRequestLine, phoneToDelete); int tempID = idOfSpecPhone(iPhones, phoneToDelete); if (tempID >= 0) { summary = summary - (iPhones[tempID].getPrice() * Integer.parseInt(iPhones[tempID].getNumber())); } iPhones[tempID].setNumber("0"); session.setAttribute("phonesRequestLine", phonesRequestLine); } session.setAttribute("summary", summary); RequestDispatcher dispatcher = request.getRequestDispatcher("cart.jsp?lang=" + (String) session.getAttribute("lang")); dispatcher.forward(request, response); }