Example usage for javax.servlet.http HttpServletRequest getServletPath

List of usage examples for javax.servlet.http HttpServletRequest getServletPath

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getServletPath.

Prototype

public String getServletPath();

Source Link

Document

Returns the part of this request's URL that calls the servlet.

Usage

From source file:net.lightbody.bmp.proxy.jetty.servlet.AdminServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getQueryString() != null && request.getQueryString().length() > 0) {
        String target = doAction(request);
        response.sendRedirect(request.getContextPath() + request.getServletPath()
                + (request.getPathInfo() != null ? request.getPathInfo() : "")
                + (target != null ? ("#" + target) : ""));
        return;/*from w ww .j a v a 2 s  .  c  o  m*/
    }

    Page page = new Page();
    page.title(getServletInfo());
    page.addHeader("");
    page.attribute("text", "#000000");
    page.attribute(Page.BGCOLOR, "#FFFFFF");
    page.attribute("link", "#606CC0");
    page.attribute("vlink", "#606CC0");
    page.attribute("alink", "#606CC0");

    page.add(new Block(Block.Bold).add(new Font(3, true).add(getServletInfo())));
    page.add(Break.rule);
    Form form = new Form(request.getContextPath() + request.getServletPath() + "?A=exit");
    form.method("GET");
    form.add(new Input(Input.Submit, "A", "Exit All Servers"));
    page.add(form);
    page.add(Break.rule);
    page.add(new Heading(3, "Components:"));

    List sList = new List(List.Ordered);
    page.add(sList);

    String id1;
    int i1 = 0;
    Iterator s = _servers.iterator();
    while (s.hasNext()) {
        id1 = "" + i1++;
        HttpServer server = (HttpServer) s.next();
        Composite sItem = sList.newItem();
        sItem.add("<B>HttpServer&nbsp;");
        sItem.add(lifeCycle(request, id1, server));
        sItem.add("</B>");
        sItem.add(Break.line);
        sItem.add("<B>Listeners:</B>");
        List lList = new List(List.Unordered);
        sItem.add(lList);

        HttpListener[] listeners = server.getListeners();
        for (int i2 = 0; i2 < listeners.length; i2++) {
            HttpListener listener = listeners[i2];
            String id2 = id1 + ":" + listener;
            lList.add(lifeCycle(request, id2, listener));
        }

        Map hostMap = server.getHostMap();

        sItem.add("<B>Contexts:</B>");
        List hcList = new List(List.Unordered);
        sItem.add(hcList);
        Iterator i2 = hostMap.entrySet().iterator();
        while (i2.hasNext()) {
            Map.Entry hEntry = (Map.Entry) (i2.next());
            String host = (String) hEntry.getKey();

            PathMap contexts = (PathMap) hEntry.getValue();
            Iterator i3 = contexts.entrySet().iterator();
            while (i3.hasNext()) {
                Map.Entry cEntry = (Map.Entry) (i3.next());
                String contextPath = (String) cEntry.getKey();
                java.util.List contextList = (java.util.List) cEntry.getValue();

                Composite hcItem = hcList.newItem();
                if (host != null)
                    hcItem.add("Host=" + host + ":");
                hcItem.add("ContextPath=" + contextPath);

                String id3 = id1 + ":" + host + ":"
                        + (contextPath.length() > 2 ? contextPath.substring(0, contextPath.length() - 2)
                                : contextPath);

                List cList = new List(List.Ordered);
                hcItem.add(cList);
                for (int i4 = 0; i4 < contextList.size(); i4++) {
                    String id4 = id3 + ":" + i4;
                    Composite cItem = cList.newItem();
                    HttpContext hc = (HttpContext) contextList.get(i4);
                    cItem.add(lifeCycle(request, id4, hc));
                    cItem.add("<BR>ResourceBase=" + hc.getResourceBase());
                    cItem.add("<BR>ClassPath=" + hc.getClassPath());

                    List hList = new List(List.Ordered);
                    cItem.add(hList);
                    int handlers = hc.getHandlers().length;
                    for (int i5 = 0; i5 < handlers; i5++) {
                        String id5 = id4 + ":" + i5;
                        HttpHandler handler = hc.getHandlers()[i5];
                        Composite hItem = hList.newItem();
                        hItem.add(lifeCycle(request, id5, handler, handler.getName()));
                        if (handler instanceof ServletHandler) {
                            hItem.add("<BR>" + ((ServletHandler) handler).getServletMap());
                        }
                    }
                }
            }
        }
        sItem.add("<P>");
    }

    response.setContentType("text/html");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache,no-store");
    Writer writer = response.getWriter();
    page.write(writer);
    writer.flush();
}

From source file:com.admc.jcreole.CreoleToHtmlHandler.java

public void handleRequest(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    File css;/*from  w  w w  . j a v  a2 s. c  om*/
    URL url;
    StringBuilder readmeSb = null;
    File fsDirFile = null;
    List<String> cssHrefs = new ArrayList<String>();
    File servletPathFile = new File(req.getServletPath());
    if (contextPath == null) {
        contextPath = application.getContextPath();
        iwUrls.put("home", contextPath);
        String appName = application.getServletContextName();
        iwLabels.put("home", ((appName == null) ? "Site" : appName) + " Home Page");
    }
    InputStream bpStream = null;
    Matcher matcher = servletFilePattern.matcher(servletPathFile.getName());
    if (!matcher.matches())
        throw new ServletException("Servlet " + getClass().getName()
                + " only supports servlet paths ending with '.html':  " + servletPathFile.getAbsolutePath());
    File crRootedDir = servletPathFile.getParentFile();
    // crRootedDir is the parent dir of the requested path.
    String pageBaseName = matcher.group(1);
    String absUrlDirPath = contextPath + crRootedDir.getAbsolutePath();
    String absUrlBasePath = absUrlDirPath + '/' + pageBaseName;
    File creoleFile = new File((isRootAbsolute ? "" : "/") + creoleRoot + crRootedDir.getAbsolutePath(),
            pageBaseName + ".creole");
    // creoleFile is a /-path either absolute or CR-rooted
    InputStream creoleStream = null;
    creoleStream = isRootAbsolute ? (creoleFile.isFile() ? new FileInputStream(creoleFile) : null)
            : application.getResourceAsStream(creoleFile.getAbsolutePath());
    if (indexer != null) {
        if (isRootAbsolute) {
            fsDirFile = creoleFile.getParentFile();
            if (!fsDirFile.isDirectory())
                fsDirFile = null;
        } else {
            fsDirFile = new File(application.getRealPath(creoleFile.getParentFile().getAbsolutePath()));
        }
        if (fsDirFile != null && !fsDirFile.isDirectory())
            throw new ServletException(
                    "fsDirFile unexpectedly not a directory: " + fsDirFile.getAbsolutePath());
    }
    if (pageBaseName.equals("index")) {
        File readmeFile = new File(creoleFile.getParentFile(), "readme.creole");
        InputStream readmeStream = isRootAbsolute
                ? (readmeFile.isFile() ? new FileInputStream(readmeFile) : null)
                : application.getResourceAsStream(readmeFile.getAbsolutePath());
        readmeSb = new StringBuilder("----\n");
        if (readmeStream == null) {
            readmeSb.append("{{{\n");
            readmeStream = application
                    .getResourceAsStream(new File(crRootedDir, "readme.txt").getAbsolutePath());
            if (readmeStream != null) {
                readmeSb.append(IOUtil.toStringBuilder(readmeStream));
                readmeSb.append("\n}}}\n");
            }
        } else {
            readmeSb.append(IOUtil.toStringBuilder(readmeStream));
        }
        if (readmeStream == null)
            readmeSb = null;
    }

    boolean inAncestorDir = false;
    File tmpDir;
    tmpDir = crRootedDir;
    while (tmpDir != null) {
        // Search from crRootedDir to creoleRoot for auxilliary files
        File curDir = new File((isRootAbsolute ? "" : "/") + creoleRoot + tmpDir.getAbsolutePath());
        File bpFile = new File(curDir, "boilerplate.html");
        if (bpStream == null)
            bpStream = isRootAbsolute ? (bpFile.isFile() ? new FileInputStream(bpFile) : null)
                    : application.getResourceAsStream(bpFile.getAbsolutePath());
        url = application.getResource(new File(tmpDir, "site.css").getAbsolutePath());
        if (url != null)
            cssHrefs.add(0, new File(contextPath + tmpDir, "site.css").getAbsolutePath());
        if (creoleStream == null && inAncestorDir && pageBaseName.equals("index") && autoIndexing) {
            File indexFile = new File(curDir, "index.creole");
            creoleStream = isRootAbsolute ? (indexFile.isFile() ? new FileInputStream(indexFile) : null)
                    : application.getResourceAsStream(indexFile.getAbsolutePath());
        }
        tmpDir = tmpDir.getParentFile();
        inAncestorDir = true;
    }
    if (creoleStream == null)
        throw new ServletException("Failed to access:  " + creoleFile.getAbsolutePath());
    if (bpStream == null)
        throw new ServletException("Failed to access 'boilerplate.html' " + "from creole dir or ancestor dir");
    tmpDir = crRootedDir;
    while (tmpDir != null) {
        url = application.getResource(new File(tmpDir, "jcreole.css").getAbsolutePath());
        if (url != null)
            cssHrefs.add(0, new File(contextPath + tmpDir, "jcreole.css").getAbsolutePath());
        tmpDir = tmpDir.getParentFile();
    }

    JCreole jCreole = new JCreole(IOUtil.toString(bpStream));
    Expander htmlExpander = jCreole.getHtmlExpander();
    Date now = new Date();
    htmlExpander.put("isoDateTime", isoDateTimeFormatter.format(now), false);
    htmlExpander.put("isoDate", isoDateFormatter.format(now), false);
    htmlExpander.put("contextPath", contextPath, false);
    htmlExpander.put("pageBaseName", pageBaseName, false);
    htmlExpander.put("pageDirPath", absUrlDirPath, false);
    htmlExpander.put("pageTitle", absUrlBasePath, false);
    if (readmeSb == null) {
        htmlExpander.put("readmeContent", "");
    } else {
        JCreole readmeJCreole = new JCreole();
        readmeJCreole.setHtmlExpander(htmlExpander);
        readmeJCreole.setInterWikiMapper(this);
        readmeJCreole.setPrivileges(jcreolePrivs);
        htmlExpander.put("readmeContent", readmeJCreole.postProcess(readmeJCreole.parseCreole(readmeSb), "\n"),
                false);
    }
    if (fsDirFile != null) {
        FileComparator.SortBy sortBy = FileComparator.SortBy.NAME;
        boolean ascending = true;
        String sortStr = req.getParameter("sort");
        if (sortStr != null) {
            Matcher m = sortParamPattern.matcher(sortStr);
            if (!m.matches())
                throw new ServletException("Malformatted sort value: " + sortStr);
            ascending = m.group(1).equals("+");
            try {
                sortBy = Enum.valueOf(FileComparator.SortBy.class, m.group(2));
            } catch (Exception e) {
                throw new ServletException("Malformatted sort string: " + sortStr);
            }
        }
        htmlExpander.put("index",
                "\n" + indexer.generateTable(fsDirFile, absUrlDirPath, true, sortBy, ascending), false);
        // An alternative for using the Tomcat-like Indexer in a
        // htmlExpander would be to write a Creole table to a
        // creoleExpander.
    }

    /* Set up Creole macros like this:
    Expander creoleExpander =
        new Expander(Expander.PairedDelims.RECTANGULAR);
    creoleExpander.put("testMacro", "\n\n<<prettyPrint>>\n{{{\n"
        + "!/bin/bash -p\n\ncp /etc/inittab /tmp\n}}}\n");
    jCreole.setCreoleExpander(creoleExpander);
    */

    if (cssHrefs.size() > 0)
        jCreole.addCssHrefs(cssHrefs);
    jCreole.setInterWikiMapper(this);
    jCreole.setPrivileges(jcreolePrivs);
    String html = jCreole.postProcess(jCreole.parseCreole(IOUtil.toStringBuilder(creoleStream)), "\n");
    resp.setBufferSize(1024);
    resp.setContentType("text/html");
    resp.getWriter().print(html);
}

From source file:com.jsmartframework.web.manager.ServletControl.java

private String getRedirectPath(String path, HttpServletRequest request, boolean authNeeded) {
    StringBuilder nextUrl = new StringBuilder();

    if (authNeeded) {
        nextUrl.append("?").append(NEXT_URL).append("=");

        if (!request.getContextPath().equals("/")) {
            nextUrl.append(request.getContextPath());
        }/*from w  w w. j a va2  s.c  o  m*/
        nextUrl.append(request.getServletPath());

        if (StringUtils.isNotBlank(request.getPathInfo())) {
            nextUrl.append(request.getPathInfo());
        }
        if (StringUtils.isNotBlank(request.getQueryString())) {
            nextUrl.append(encodeUrlQuietly("?" + request.getQueryString()));
        }
    } else {
        String nextPath = request.getParameter(NEXT_URL);
        if (StringUtils.isNotBlank(nextPath)) {
            return nextPath;
        }
    }
    return (path.startsWith("/") ? request.getContextPath() : "") + path + nextUrl;
}

From source file:org.red5.stream.http.servlet.TransportSegmentFeeder.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)/*from  ww  w  . ja v  a2  s. c om*/
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    log.debug("Segment feed requested");
    // get red5 context and segmenter
    if (service == null) {
        ApplicationContext appCtx = (ApplicationContext) getServletContext()
                .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        service = (SegmenterService) appCtx.getBean("segmenter.service");
    }
    // get the requested stream / segment
    String servletPath = request.getServletPath();
    String streamName = servletPath.split("\\.")[0];
    log.debug("Stream name: {}", streamName);
    if (service.isAvailable(streamName)) {
        response.setContentType("video/MP2T");
        // data segment
        Segment segment = null;
        // setup buffers and output stream
        byte[] buf = new byte[188];
        ByteBuffer buffer = ByteBuffer.allocate(188);
        ServletOutputStream sos = response.getOutputStream();
        // loop segments
        while ((segment = service.getSegment(streamName)) != null) {
            do {
                buffer = segment.read(buffer);
                // log.trace("Limit - position: {}", (buffer.limit() - buffer.position()));
                if ((buffer.limit() - buffer.position()) == 188) {
                    buffer.get(buf);
                    // write down the output stream
                    sos.write(buf);
                } else {
                    log.info("Segment result has indicated a problem");
                    // verifies the currently requested stream segment
                    // number against the currently active segment
                    if (service.getSegment(streamName) == null) {
                        log.debug("Requested segment is no longer available");
                        break;
                    }
                }
                buffer.clear();
            } while (segment.hasMoreData());
            log.trace("Segment {} had no more data", segment.getIndex());
            // flush
            sos.flush();
            // segment had no more data
            segment.cleanupThreadLocal();
        }
        buffer.clear();
        buffer = null;
    } else {
        // let requester know that stream segment is not available
        response.sendError(404, "Requested segmented stream not found");
    }
}

From source file:com.apress.progwt.server.web.controllers.SignupIfPossibleController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse arg1)
        throws Exception {

    if (userService.nowAcceptingSignups()) {
        Map<String, Object> model = new HashMap<String, Object>();
        CreateUserRequestCommand comm = new CreateUserRequestCommand();

        Calendar c = Calendar.getInstance();
        c.get(Calendar.DAY_OF_WEEK_IN_MONTH);
        String secretKey = CryptUtils
                .hashString(invitationService.getSalt() + c.get(Calendar.DAY_OF_WEEK_IN_MONTH));

        model.put("hideSecretKey", true);
        model.put("secretkey", secretKey);

        if (req.getServletPath().contains("2")) {
            return new ModelAndView("redirect:signup2.html", model);
        } else {/*from   w  ww  . ja v  a  2s  . com*/
            return new ModelAndView("redirect:signup.html", model);
        }

    } else {
        return new ModelAndView(getMailingListView());
    }
}

From source file:flex.webtier.server.j2ee.MxmlServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    try {//from  ww w .  j a  v  a 2s .c  o m
        // encoding must be set before any access to request parameters
        request.setCharacterEncoding("UTF-8");

        MxmlContext context = new MxmlContext();
        context.setRequest(request);
        context.setResponse(response);
        context.setServletContext(getServletContext());
        context.setPageTitle(request.getServletPath());
        setupMxmlContextKeys(getServletContext(), context, request);
        context.setDetectionSettings(DetectionSettingsFactory.getInstance(request.getContextPath()));
        context.setHistorySettings(HistorySettingsFactory.getInstance(request.getContextPath()));

        if (!ServiceFactory.getLicenseService().isMxmlCompileEnabled()) {
            response.sendError(481, "The current license does not support this feature.");
            ServiceFactory.getLogger().logError(
                    "The current license does not support this feature. request=" + request.getServletPath());
            return;
        }

        if (isObjectRequest(request)) {
            if (request.getParameter("w") != null) {
                context.setWidth(request.getParameter("w"));
            } else {
                context.setWidth("100%");
            }
            if (request.getParameter("h") != null) {
                context.setHeight(request.getParameter("h"));
            } else {
                context.setHeight("100%");
            }
            objectFilterChain.invoke(context);
        } else {
            PathResolver.setThreadLocalPathResolver(new ServletPathResolver(getServletContext()));
            flex2.compiler.common.PathResolver resolver = new flex2.compiler.common.PathResolver();
            resolver.addSinglePathResolver(
                    new flex.webtier.server.j2ee.ServletPathResolver(getServletContext()));
            resolver.addSinglePathResolver(LocalFilePathResolver.getSingleton());
            resolver.addSinglePathResolver(URLPathResolver.getSingleton());
            ThreadLocalToolkit.setPathResolver(resolver);

            // set up for localizing messages
            LocalizationManager localizationManager = new LocalizationManager();
            localizationManager.addLocalizer(new XLRLocalizer());
            localizationManager.addLocalizer(new ResourceBundleLocalizer());
            ThreadLocalToolkit.setLocalizationManager(localizationManager);

            setupCompileEventLogger(context, request);
            setupSourceCodeLoader(context);

            filterChain.invoke(context);
        }
    } catch (FileNotFoundException fnfe) {
        // return an error page
        HttpCache.setCacheHeaders(false, 0, -1, response);
        response.sendError(HttpServletResponse.SC_NOT_FOUND, fnfe.getMessage());

        if (logCompilerErrors) {
            ServiceFactory.getLogger().logError(fnfe.getMessage(), fnfe);
        }
    } catch (Throwable t) {
        // return an error page
        ServiceFactory.getLogger().logError("Unknown error " + request.getServletPath() + ": " + t.getMessage(),
                t);
        throw new ServletException(t);
    } finally {
        ServletUtils.clearThreadLocals();
    }
}

From source file:io.mapzone.arena.tracker.GoogleAnalyticsTracker.java

private void extractParams(List<NameValuePair> params, ServletRequestEvent event) {
    params.add(new BasicNameValuePair("t", "event"));
    params.add(new BasicNameValuePair("ec", "externalRequest"));
    HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
    if (request != null) {
        try {//from w  w w  .j  a va2  s.  co m
            // TODO, add user or session or something else here authToken
            String clientId = "anonymous";
            String authToken = request.getParameter("authToken");
            if (!StringUtils.isBlank(authToken)) {
                clientId = authToken;
            }
            addEncoded(params, "cid", clientId);

            // request.get
            String context = request.getServletPath();
            int index = context.lastIndexOf("/");
            if (index != -1) {
                context = context.substring(index + 1);
            }
            addEncoded(params, "ea", context);
            if (!StringUtils.isBlank(request.getContentType())) {
                index = request.getContentType().toLowerCase().lastIndexOf("charset=");
                if (index != -1) {
                    addEncoded(params, "de", request.getContentType().substring(index + 8));
                }
            }
            addEncoded(params, "dl", request.getServletPath() + "?" + request.getQueryString());
            addEncoded(params, "el", request.getQueryString());
            addEncoded(params, "dr", request.getHeader("Referer"));
            addEncoded(params, "ua", request.getHeader("User-Agent"));
            addEncoded(params, "uip", request.getRemoteAddr());
        } catch (UnsupportedEncodingException e) {
            // do nothing
            log.error(e);
        }

    }
}

From source file:it.cnr.icar.eric.server.interfaces.soap.RegistryBSTServlet.java

@SuppressWarnings("unused")
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");

    String requestUri = req.getRequestURI();
    String servletPath = req.getServletPath();
    String scheme = req.getScheme();
    String serverName = req.getServerName();
    String queryString = req.getQueryString();
    String ericName = RegistryProperties.getInstance().getProperty("eric.name", "eric");
    int serverPort = req.getServerPort();
    StringBuffer sb = new StringBuffer();
    sb.append(scheme).append("://").append(serverName).append(':');
    sb.append(serverPort);//  www.j a  v  a  2s  . c  o  m
    sb.append('/');
    sb.append(ericName);
    sb.append("/registry/thin/browser.jsp");
    String url = sb.toString();

    PrintWriter wt = resp.getWriter();
    wt.println(ServerResourceBundle.getInstance().getString("message.urlForSOAP"));
    wt.println(ServerResourceBundle.getInstance().getString("message.urlForWebAccess", new Object[] { url }));
    wt.flush();
    wt.close();
}

From source file:com.ekitap.controller.AdminUrunController.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  ww w  . j a v  a 2s .  c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    response.setCharacterEncoding("ISO-8859-9");
    String adminPath = request.getServletPath();
    String url = null;
    String adi = request.getParameter("adi");
    ArrayList<KategoriBean> liste = null;
    ArrayList<YazarBean> yazarListe = null;
    ArrayList<YayinEviBean> yayinEviListe = null;
    ArrayList<UrunlerBean> urunListe = null;
    ArrayList<UrunlerBean> urunGuncelListe = null;
    ArrayList<UrunResimBean> liste_resim = null;
    ArrayList liste_fiyat = null;
    ArrayList<OzellikBean> liste_ozellik;
    ArrayList<UrunOzellikBean> liste_urun_ozellik;
    ArrayList<StokBean> liste_stok;
    int sayfa = 1;
    int sayfaSayisi = (int) UrunlerDAO.sayfaSayisi(UrunlerDAO.getUrunAdet(), sayfaBasinaUrun);
    if (adminPath.equals("/urungoster")) {
        System.out.println(request.getParameter("id"));
        try {
            sayfa = Integer.parseInt(request.getParameter("id"));
            if (sayfa <= 0 || sayfa > sayfaSayisi) {
                sayfa = 1;
            }
        } catch (Exception e) {
            sayfa = 1;
        }

        int baslangicSayisi = (sayfa - 1) * sayfaBasinaUrun;
        urunListe = UrunlerDAO.getUrunListele(baslangicSayisi, sayfaBasinaUrun);
        if (urunListe != null) {
            request.setAttribute("urunliste", urunListe);
            request.setAttribute("sayfasayisi", sayfaSayisi);
        }

        url = "/WEB-INF/view/adminpanel" + adminPath + ".jsp";
        request.getRequestDispatcher(url).forward(request, response);
    } else if (adminPath.equals("/urunekle")) {
        if (adi == null || adi.trim().isEmpty()) {
            liste = KategoriDAO.getKategoriListele();
            yazarListe = YazarDAO.getYazarListele();
            yayinEviListe = YayinEviDAO.getYayinEviListele();
            if (liste != null) {
                request.setAttribute("katliste", liste);
            }
            if (yazarListe != null) {
                request.setAttribute("yazarliste", yazarListe);
            }
            if (yayinEviListe != null) {
                request.setAttribute("yayinliste", yayinEviListe);
            }

            url = "/WEB-INF/view/adminpanel" + adminPath + ".jsp";
            request.getRequestDispatcher(url).forward(request, response);
        }
        // rn ekle
        else {
            int urunid;
            try {
                //   System.out.println(request.getParameter("urunID"));
                urunid = Integer.parseInt(request.getParameter("urunID"));
                // System.out.println(urunid);
            } catch (Exception e) {
                urunid = 0;
            }

            //                int yayin = Integer.parseInt(request.getParameter("yayin"));
            //                int yazar = Integer.parseInt(request.getParameter("yazar"));
            int katidd = Integer.parseInt(request.getParameter("katidd"));
            UrunlerBean urunler = new UrunlerBean(0, request.getParameter("adi"), 0, 0, katidd,
                    request.getParameter("aciklama"));
            int urunID = UrunlerDAO.setUrunEkle(urunler, urunid);

            adminPath = "/urunguncelle";
            response.sendRedirect("/urunguncelle?urunID=" + urunID);
            //                url = "/WEB-INF/view/adminpanel" + adminPath + ".jsp";
            //            request.getRequestDispatcher(url).forward(request, response);
        }

    } else if (adminPath.equals("/urunguncelle")) {
        liste = KategoriDAO.getKategoriListele();
        yazarListe = YazarDAO.getYazarListele();
        yayinEviListe = YayinEviDAO.getYayinEviListele();
        String urunid = request.getParameter("urunID");
        liste_resim = UrunlerDAO.getResimListele(Integer.parseInt(urunid));
        liste_fiyat = UrunlerDAO.getUrunFiyat(Integer.parseInt(urunid));
        liste_ozellik = UrunlerDAO.getOzellik();
        liste_urun_ozellik = UrunlerDAO.getUrunOzellik(Integer.parseInt(urunid));
        liste_stok = UrunlerDAO.getUrunStok(Integer.parseInt(urunid));
        if (urunid == null || urunid.trim().isEmpty()) {
            return;
        }
        urunGuncelListe = UrunlerDAO.getUrunGuncelBilgi(urunid);
        if (liste != null) {
            request.setAttribute("katliste", liste);
        }
        if (yazarListe != null) {
            request.setAttribute("yazarliste", yazarListe);
        }
        if (yayinEviListe != null) {
            request.setAttribute("yayinliste", yayinEviListe);
        }
        if (urunGuncelListe != null) {
            request.setAttribute("guncelurun", urunGuncelListe);
        }
        if (liste_resim != null) {
            request.setAttribute("resimliste", liste_resim);
        }
        if (liste_fiyat != null) {
            request.setAttribute("fiyatliste", liste_fiyat);
        }
        if (liste_ozellik != null) {
            request.setAttribute("ozellikliste", liste_ozellik);
        }
        if (liste_urun_ozellik != null) {
            request.setAttribute("urunozellikliste", liste_urun_ozellik);
        }
        if (liste_stok != null) {
            request.setAttribute("stokliste", liste_stok);
        }
        url = "/WEB-INF/view/adminpanel" + adminPath + ".jsp";
        request.getRequestDispatcher(url).forward(request, response);
    } else if (adminPath.equals("/yazarekle")) {
        System.out.println(request.getParameter("yazaradi"));
        //burdan cek
        YazarBean yazar = new YazarBean(0, request.getParameter("yazarad"), request.getParameter("yazarsoyad"),
                request.getParameter("yazarmail"));
        //  System.out.println(request.getParameter("yazarad")+request.getParameter("yazarsoyad")+request.getParameter("yazarmail"));
        YazarDAO.setYazarEkle(yazar);
    } else if (adminPath.equals("/yayineviekle")) {
        YayinEviBean yayinEvi = new YayinEviBean(0, request.getParameter("yayinad"),
                request.getParameter("yayinadres"), request.getParameter("yayinmail"));
        YayinEviDAO.setYayinEviEkle(yayinEvi);

    } else if (adminPath.equals("/resimekle")) {
        int urunID = Integer.parseInt(request.getParameter("urunID"));

        System.out.println(urunID);
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        String name = null;
        // process only if it is multipart content
        if (isMultipart) {
            // Create a factory for disk-based file items
            FileItemFactory factory = new DiskFileItemFactory();

            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);
            try {
                // Parse the request
                List<FileItem> multiparts = upload.parseRequest(request);

                for (FileItem item : multiparts) {
                    if (!item.isFormField()) {
                        name = new File(item.getName()).getName();
                        item.write(new File(UPLOAD_DIRECTORY + File.separator + name));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        liste_resim = UrunlerDAO.resimKaydet(urunID, name);
        request.setAttribute("resimliste", liste_resim);
        url = "/WEB-INF/view/adminpanel" + adminPath + ".jsp";
        request.getRequestDispatcher(url).forward(request, response);
    } else if (adminPath.equals("/fiyatekle")) {
        float vergiOnce = Float.parseFloat(request.getParameter("vergionce"));
        float vergiSonra = Float.parseFloat(request.getParameter("vergisonra"));
        int urunID = Integer.parseInt(request.getParameter("urunID"));

        UrunlerDAO.setUrunFiyat(urunID, vergiOnce, vergiSonra);
    } else if (adminPath.equals("/ozellikekle")) {
        String urunid = request.getParameter("urunID");
        if (urunid == null || urunid.trim().isEmpty()) {
            return;
        }
        int i = 1;
        ArrayList<UrunOzellikBean> a = new ArrayList();
        UrunOzellikBean urunOzellik;
        while (request.getParameter("field" + Integer.toString(i)) != null) {
            urunOzellik = new UrunOzellikBean(Integer.parseInt(urunid),
                    Integer.parseInt(request.getParameter("ofield" + Integer.toString(i))),
                    request.getParameter("field" + Integer.toString(i)));
            a.add(urunOzellik);

            i++;
        }
        UrunlerDAO.setUrunOzellik(a);
        //            for (UrunOzellikBean object : a) {
        //                System.out.println(object.getDeger()+object.getOzellikID());
        //            }

    } else if (adminPath.equals("/stokekle")) {
        String urunid = request.getParameter("urunID");
        if (urunid == null || urunid.trim().isEmpty()) {
            return;
        }
        try {
            int stok = Integer.parseInt(request.getParameter("stok"));

            UrunlerDAO.setUrunStok(new StokBean(0, Integer.parseInt(urunid), stok));
        } catch (Exception e) {
        }
    }
}

From source file:org.openqa.grid.internal.TestSession.java

private HttpRequest prepareProxyRequest(HttpServletRequest request
/*, ForwardConfiguration config*/) throws IOException {
    URL remoteURL = slot.getRemoteURL();

    String pathSpec = request.getServletPath() + request.getContextPath();
    String path = request.getRequestURI();
    if (!path.startsWith(pathSpec)) {
        throw new IllegalStateException("Expected path " + path + " to start with pathSpec " + pathSpec);
    }/*w w w. j a  va 2 s .  c o  m*/
    String end = path.substring(pathSpec.length());
    String ok = remoteURL + end;
    if (request.getQueryString() != null) {
        ok += "?" + request.getQueryString();
    }
    String uri = new URL(remoteURL, ok).toExternalForm();

    InputStream body = null;
    if (request.getContentLength() > 0 || request.getHeader("Transfer-Encoding") != null) {
        body = request.getInputStream();
    }

    HttpRequest proxyRequest;

    if (body != null) {
        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest(request.getMethod(), uri);
        r.setEntity(new InputStreamEntity(body, request.getContentLength()));
        proxyRequest = r;
    } else {
        proxyRequest = new BasicHttpRequest(request.getMethod(), uri);
    }

    for (Enumeration<?> e = request.getHeaderNames(); e.hasMoreElements();) {
        String headerName = (String) e.nextElement();

        if ("Content-Length".equalsIgnoreCase(headerName)) {
            continue; // already set
        }

        proxyRequest.setHeader(headerName, request.getHeader(headerName));
    }
    return proxyRequest;
}