Example usage for javax.servlet.http HttpServletResponse setCharacterEncoding

List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setCharacterEncoding.

Prototype

public void setCharacterEncoding(String charset);

Source Link

Document

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.

Usage

From source file:org.jamwiki.servlets.StylesheetServlet.java

/**
 *
 *///from  ww  w.j av  a  2s.co  m
public ModelAndView handleJAMWikiRequest(HttpServletRequest request, HttpServletResponse response,
        ModelAndView next, WikiPageInfo pageInfo) throws Exception {
    String virtualWiki = pageInfo.getVirtualWikiName();
    String stylesheet = ServletUtil.cachedContent(request.getContextPath(), request.getLocale(), virtualWiki,
            WikiBase.SPECIAL_PAGE_SYSTEM_CSS, false);
    stylesheet += '\n' + ServletUtil.cachedContent(request.getContextPath(), request.getLocale(), virtualWiki,
            WikiBase.SPECIAL_PAGE_CUSTOM_CSS, false);
    response.setContentType("text/css");
    response.setCharacterEncoding("UTF-8");
    // cache for 30 minutes (60 * 30 = 1800)
    // FIXME - make configurable
    response.setHeader("Cache-Control", "max-age=1800");
    PrintWriter out = response.getWriter();
    out.print(stylesheet);
    out.close();
    // do not load defaults or redirect - return as raw CSS
    return null;
}

From source file:com.socialization.util.ConnectorServlet.java

/**
 * Manage the <code>POST</code> requests (<code>FileUpload</code>).<br />
 * /* w ww.j av  a 2  s  .c  o m*/
 * The servlet accepts commands sent in the following format:<br />
 * <code>connector?Command=&lt;FileUpload&gt;&Type=&lt;ResourceType&gt;&CurrentFolder=&lt;FolderPath&gt;</code>
 * with the file in the <code>POST</code> body.<br />
 * <br>
 * It stores an uploaded file (renames a file if another exists with the same name) and then
 * returns the JavaScript callback.
 */
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    logger.debug("Entering Connector#doPost");

    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html; charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    PrintWriter out = response.getWriter();

    String commandStr = request.getParameter("Command");
    String typeStr = request.getParameter("Type");
    String currentFolderStr = request.getParameter("CurrentFolder");

    logger.debug("Parameter Command: {}", commandStr);
    logger.debug("Parameter Type: {}", typeStr);
    logger.debug("Parameter CurrentFolder: {}", currentFolderStr);

    UploadResponse ur;

    // if this is a QuickUpload request, 'commandStr' and 'currentFolderStr'
    // are empty
    if (Utils.isEmpty(commandStr) && Utils.isEmpty(currentFolderStr)) {
        commandStr = "QuickUpload";
        currentFolderStr = "/";
    }

    if (!RequestCycleHandler.isEnabledForFileUpload(request))
        ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR, null, null,
                Messages.NOT_AUTHORIZED_FOR_UPLOAD);
    else if (!CommandHandler.isValidForPost(commandStr))
        ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_COMMAND);
    else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr))
        ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_TYPE);
    else if (!UtilsFile.isValidPath(currentFolderStr))
        ur = UploadResponse.UR_INVALID_CURRENT_FOLDER;
    else {
        ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr);

        String typeDirPath = null;
        if ("File".equals(typeStr)) {
            //  ${application.path}/WEB-INF/userfiles/
            typeDirPath = getServletContext().getRealPath("WEB-INF/userfiles/");
        } else {
            String typePath = UtilsFile.constructServerSidePath(request, resourceType);
            typeDirPath = getServletContext().getRealPath(typePath);
        }

        File typeDir = new File(typeDirPath);
        UtilsFile.checkDirAndCreate(typeDir);

        File currentDir = new File(typeDir, currentFolderStr);

        if (!currentDir.exists())
            ur = UploadResponse.UR_INVALID_CURRENT_FOLDER;
        else {

            String newFilename = null;
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);

            upload.setHeaderEncoding("UTF-8");

            try {

                List<FileItem> items = upload.parseRequest(request);

                // We upload only one file at the same time
                FileItem uplFile = items.get(0);
                String rawName = UtilsFile.sanitizeFileName(uplFile.getName());
                String filename = FilenameUtils.getName(rawName);
                String baseName = FilenameUtils.removeExtension(filename);
                String extension = FilenameUtils.getExtension(filename);

                // ????
                if (!ExtensionsHandler.isAllowed(resourceType, extension)) {
                    ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION);
                }

                // ??
                else if (uplFile.getSize() > 1024 * 1024 * 3) {
                    // ?
                    ur = new UploadResponse(204);
                }

                // ?,  ?
                else {

                    // construct an unique file name

                    //  UUID ???, ?
                    filename = UUID.randomUUID().toString() + "." + extension;
                    filename = makeFileName(currentDir.getPath(), filename);
                    File pathToSave = new File(currentDir, filename);

                    int counter = 1;
                    while (pathToSave.exists()) {
                        newFilename = baseName.concat("(").concat(String.valueOf(counter)).concat(")")
                                .concat(".").concat(extension);
                        pathToSave = new File(currentDir, newFilename);
                        counter++;
                    }

                    if (Utils.isEmpty(newFilename))
                        ur = new UploadResponse(UploadResponse.SC_OK,
                                UtilsResponse.constructResponseUrl(request, resourceType, currentFolderStr,
                                        true, ConnectorHandler.isFullUrl()).concat(filename));
                    else
                        ur = new UploadResponse(UploadResponse.SC_RENAMED,
                                UtilsResponse.constructResponseUrl(request, resourceType, currentFolderStr,
                                        true, ConnectorHandler.isFullUrl()).concat(newFilename),
                                newFilename);

                    // secure image check
                    if (resourceType.equals(ResourceTypeHandler.IMAGE)
                            && ConnectorHandler.isSecureImageUploads()) {
                        if (UtilsFile.isImage(uplFile.getInputStream()))
                            uplFile.write(pathToSave);
                        else {
                            uplFile.delete();
                            ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION);
                        }
                    } else
                        uplFile.write(pathToSave);

                }
            } catch (Exception e) {
                ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR);
            }
        }

    }

    out.print(ur);
    out.flush();
    out.close();

    logger.debug("Exiting Connector#doPost");
}

From source file:net.nan21.dnet.core.web.controller.ui.extjs.UiExtjsFrameController.java

/**
 * Handler to return the cached js file with the dependent components.
 * //from   w w  w  .j  a v a 2 s.  c o  m
 * @param bundle
 * @param frame
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/{bundle}/{frame}.js", method = RequestMethod.GET)
@ResponseBody
public String frameCmpJs(@PathVariable("bundle") String bundle, @PathVariable("frame") String frame,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {
        @SuppressWarnings("unused")
        ISessionUser su = (ISessionUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    } catch (java.lang.ClassCastException e) {
        throw new NotAuthorizedRequestException("Not authenticated");
    }

    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");

    String fileName = frame + ".js";
    File f = new File(this.cacheFolder + "/" + bundle + "." + fileName);

    if (!f.exists()) {
        DependencyLoader loader = this.getDependencyLoader();
        loader.packFrameCmp(bundle, frame, f);
    }

    this.sendFile(f, response.getOutputStream());

    return null;
}

From source file:org.motechproject.server.outbox.web.VxmlOutboxController.java

/**
* Handles Outbox HTTP requests to remove saved in the outbox message and generates a VXML document
 * with message remove confirmation. The generated VXML document based on the msgRemovedConf.vm  Velocity template.
 *
 * The message will not be physically removed. The message status will be set to PLAYED.
 *
* <p/>//from www.  j  a v  a2 s .  com
* <p/>
* URL to request a saved VoiceXML message from outbox :
* http://<host>:<port>/<motech-platform-server>/module/outbox/vxml/remove?mId=$message.id&ln=$language>
*/
public ModelAndView remove(HttpServletRequest request, HttpServletResponse response) {
    logger.info("Removing saved message message...");

    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");

    String messageId = request.getParameter(MESSAGE_ID_PARAM);
    String language = request.getParameter(LANGUAGE_PARAM);

    String contextPath = request.getContextPath();

    ModelAndView mav = new ModelAndView();
    mav.setViewName(MESSAGE_REMOVED_CONFIRMATION_TEMPLATE_NAME);
    mav.addObject("contextPath", contextPath);
    mav.addObject("language", language);
    mav.addObject("escape", new StringEscapeUtils());

    logger.info("Message ID: " + messageId);

    if (messageId == null) {
        logger.error("Invalid request - missing parameter: " + MESSAGE_ID_PARAM);
        mav.setViewName(ERROR_MESSAGE_TEMPLATE_NAME);
        return mav;
    }

    try {
        voiceOutboxService.setMessageStatus(messageId, OutboundVoiceMessageStatus.PLAYED);
    } catch (Exception e) {
        logger.error("Can not mark the message with ID: " + messageId + " as PLAYED in the outbox", e);
        mav.setViewName(REMOVE_SAVED_MESSAGE_ERROR_TEMPLATE_NAME);
        return mav;
    }

    //TODO - get party ID proper way from security principal or authentication context when it is available
    String partyId;
    try {
        OutboundVoiceMessage message = voiceOutboxService.getMessageById(messageId);
        partyId = message.getPartyId();
    } catch (Exception e) {
        logger.error("Can not obtain message ID: " + messageId + " to get party ID");
        mav.setViewName(ERROR_MESSAGE_TEMPLATE_NAME);
        return mav;
    }

    logger.debug("partyId: " + partyId);

    mav.addObject("partyId", partyId);
    return mav;

}

From source file:com.thoughtworks.go.server.newsecurity.filters.DenyIfRefererIsNotFilesFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    if (request.getServletPath().startsWith("/files/")) {
        throw new UnsupportedOperationException("Filter should not be invoked for `/files/` urls.");
    }//from ww w .  j av  a 2  s . c om

    if (isRequestFromArtifact(request)) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

        ContentTypeAwareResponse contentTypeAwareResponse = CONTENT_TYPE_NEGOTIATION_MESSAGE_HANDLER
                .getResponse(request);
        response.setCharacterEncoding("utf-8");
        response.setContentType(contentTypeAwareResponse.getContentType().toString());
        response.getOutputStream().print(contentTypeAwareResponse
                .getFormattedMessage("Denied GoCD access for requests from artifacts."));
    } else {
        filterChain.doFilter(request, response);
    }
}

From source file:io.resthelper.RestHelperController.java

@RequestMapping(value = "/rest-helper", method = RequestMethod.GET)
public void frame(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html; charset=utf-8");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = response.getWriter();

    String requestURI = request.getRequestURI();
    String contextName = requestURI.substring(0, requestURI.indexOf("/rest-helper"));

    if (!restHelperService.isValidIp(request)) {
        throw new NotAllowIpException();
    }//from   ww  w.  j  ava  2  s.c  o  m

    out.println(
            "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">");
    out.println("<HTML>");
    out.println("<HEAD>");
    out.println("<TITLE>");
    out.println("API HELPER");
    out.println("</TITLE>");
    out.println("<SCRIPT type=\"text/javascript\">");
    out.println("    targetPage = \"\" + window.location.search;");
    out.println("    ");
    out.println("    if (targetPage != \"\" && targetPage != \"undefined\")");
    out.println("        targetPage = targetPage.substring(1);");
    out.println("    ");
    out.println("    if (targetPage.indexOf(\":\") != -1)");
    out.println("        targetPage = \"undefined\";");
    out.println("     ");
    out.println("    function loadFrames() {");
    out.println("        if (targetPage != \"\" && targetPage != \"undefined\")");
    out.println("             top.apiFrame.location = top.targetPage;");
    out.println("    }");
    out.println("</SCRIPT>");
    out.println("</HEAD>");
    out.println("<FRAMESET cols=\"25%,75%\" title=\"\" onLoad=\"top.loadFrames()\">");
    out.println("<FRAMESET rows=\"30%,70%\" title=\"\" onLoad=\"top.loadFrames()\">");
    out.println("<FRAME src=\"" + contextName
            + "/rest-helper/packages\" name=\"packageListFrame\" title=\"all packages\">");
    out.println("<FRAME src=\"about:blank\" name=\"packageFrame\" title=\"api name list for package\">");
    out.println("</FRAMESET>");
    out.println("<FRAME src=\"about:blank\" name=\"apiFrame\" title=\"apis\" scrolling=\"yes\">");
    out.println("</FRAMESET>");
    out.println("</HTML>");
    out.flush();
}

From source file:com.starit.diamond.server.controller.AdminController.java

/**
 * ??//from  w ww  .  ja v  a 2  s . c om
 * 
 * @param request
 * @param dataId
 * @param group
 * @param content
 * @param modelMap
 * @return
 */
@RequestMapping(value = "/updateConfig", method = RequestMethod.POST)
public String updateConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("description") String description, @RequestParam("content") String content,
        ModelMap modelMap) {
    response.setCharacterEncoding(Constants.ENCODE);

    String remoteIp = getRemoteIP(request);

    String userName = (String) request.getSession().getAttribute("user");
    ConfigInfo configInfo = new ConfigInfo(dataId, group, userName, content, description);
    boolean checkSuccess = true;
    String errorMessage = "?";
    if (!StringUtils.hasLength(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;
        errorMessage = "DataId";
    }
    if (!StringUtils.hasLength(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!StringUtils.hasLength(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        modelMap.addAttribute("configInfo", configInfo);
        return "/admin/detailConfig";
    }

    // ?,?
    ConfigInfo oldConfigInfo = this.configService.findConfigInfo(dataId, group);
    if (oldConfigInfo == null) {
        updateLog.warn("?,???, dataId=" + dataId + ",group=" + group);
        modelMap.addAttribute("message",
                "?, ???, dataId=" + dataId + ",group=" + group);
        return listConfig(request, response, dataId, group, 1, 20, modelMap);
    }
    String oldContent = oldConfigInfo.getContent();

    this.configService.updateConfigInfo(dataId, group, content, userName, description);

    // 
    updateLog.warn("??\ndataId=" + dataId + "\ngroup=" + group + "\noldContent=\n" + oldContent
            + "\nnewContent=\n" + content + "\nsrc ip=" + remoteIp);
    request.getSession().setAttribute("message", "???!");
    return "redirect:" + listConfig(request, response, null, null, 1, 10, modelMap);
}

From source file:net.nan21.dnet.core.web.controller.ui.extjs.UiExtjsFrameController.java

/**
 * Handler to return the cached js file with the dependent translations.
 * //  www  . j  av a  2s .c  o m
 * @param bundle
 * @param frame
 * @param language
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/{bundle}/{language}/{frame}.js", method = RequestMethod.GET)
@ResponseBody
public String frameTrlJs(@PathVariable("bundle") String bundle, @PathVariable("frame") String frame,
        @PathVariable("language") String language, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    try {
        @SuppressWarnings("unused")
        ISessionUser su = (ISessionUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    } catch (java.lang.ClassCastException e) {
        throw new NotAuthorizedRequestException("Not authenticated");
    }

    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");

    String fileName = frame + "-" + language + ".js";
    File f = new File(this.cacheFolder + "/" + bundle + "." + fileName);
    if (!f.exists()) {
        DependencyLoader loader = this.getDependencyLoader();
        loader.packFrameTrl(bundle, frame, language, f);
    }

    this.sendFile(f, response.getOutputStream());
    return null;
}

From source file:ch.ralscha.extdirectspring.controller.ApiController.java

/**
 * Method that handles api.js and api-debug.js calls. Generates a javascript with the
 * necessary code for Ext Direct./* w  ww. j  a v a2 s .  c  o  m*/
 *
 * @param apiNs name of the namespace the variable remotingApiVar will live in.
 * Defaults to Ext.app
 * @param actionNs name of the namespace the action will live in.
 * @param remotingApiVar name of the remoting api variable. Defaults to REMOTING_API
 * @param pollingUrlsVar name of the polling urls object. Defaults to POLLING_URLS
 * @param group name of the api group. Multiple groups delimited with comma
 * @param fullRouterUrl if true the router property contains the full request URL with
 * method, server and port. Defaults to false returns only the URL without method,
 * server and port
 * @param format only valid value is "json2. Ext Designer sends this parameter and the
 * response is a JSON. Defaults to null and response is Javascript.
 * @param baseRouterUrl Sets the path to the router and poll controllers. If set
 * overrides default behavior that uses request.getRequestURI
 * @param request the HTTP servlet request
 * @param response the HTTP servlet response
 * @throws IOException
 */
@SuppressWarnings({ "resource" })
@RequestMapping(value = { "/api.js", "/api-debug.js", "/api-debug-doc.js" }, method = RequestMethod.GET)
public void api(@RequestParam(value = "apiNs", required = false) String apiNs,
        @RequestParam(value = "actionNs", required = false) String actionNs,
        @RequestParam(value = "remotingApiVar", required = false) String remotingApiVar,
        @RequestParam(value = "pollingUrlsVar", required = false) String pollingUrlsVar,
        @RequestParam(value = "group", required = false) String group,
        @RequestParam(value = "fullRouterUrl", required = false) Boolean fullRouterUrl,
        @RequestParam(value = "format", required = false) String format,
        @RequestParam(value = "baseRouterUrl", required = false) String baseRouterUrl,
        HttpServletRequest request, HttpServletResponse response) throws IOException {

    if (format == null) {
        response.setContentType(this.configurationService.getConfiguration().getJsContentType());
        response.setCharacterEncoding(ExtDirectSpringUtil.UTF8_CHARSET.name());

        String apiString = buildAndCacheApiString(apiNs, actionNs, remotingApiVar, pollingUrlsVar, group,
                fullRouterUrl, baseRouterUrl, request);

        byte[] outputBytes = apiString.getBytes(ExtDirectSpringUtil.UTF8_CHARSET);
        response.setContentLength(outputBytes.length);

        ServletOutputStream outputStream = response.getOutputStream();
        outputStream.write(outputBytes);
        outputStream.flush();
    } else {
        response.setContentType(RouterController.APPLICATION_JSON.toString());
        response.setCharacterEncoding(RouterController.APPLICATION_JSON.getCharset().name());

        String requestUrlString = request.getRequestURL().toString();

        boolean debug = requestUrlString.contains("api-debug.js");
        String routerUrl = requestUrlString.replaceFirst("api[^/]*?\\.js", "router");

        String apiString = buildApiJson(apiNs, actionNs, remotingApiVar, routerUrl, group, debug);
        byte[] outputBytes = apiString.getBytes(ExtDirectSpringUtil.UTF8_CHARSET);
        response.setContentLength(outputBytes.length);

        ServletOutputStream outputStream = response.getOutputStream();
        outputStream.write(outputBytes);
        outputStream.flush();
    }
}

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

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// www.  j  a  v a 2  s .  co  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) {
        }
    }
}