Java Code Examples for javax.servlet.ServletRequest#getCharacterEncoding()
The following examples show how to use
javax.servlet.ServletRequest#getCharacterEncoding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SetCharacterEncodingFilter.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param chain The filter chain we are processing * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding() == null)) { String characterEncoding = selectEncoding(request); if (characterEncoding != null) { request.setCharacterEncoding(characterEncoding); } } // Pass control on to the next filter chain.doFilter(request, response); }
Example 2
Source File: SetCharacterEncodingFilter.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param chain The filter chain we are processing * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used if ((request.getCharacterEncoding() == null)) { String encodingIn = selectEncoding(request); if (encoding != null) { request.setCharacterEncoding(encodingIn); response.setContentType("text/html; charset=" + encodingIn); response.setCharacterEncoding(encodingIn); } } // Pass control on to the next filter chain.doFilter(request, response); }
Example 3
Source File: SetCharacterEncodingFilter.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param chain The filter chain we are processing * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding() == null)) { String characterEncoding = selectEncoding(request); if (characterEncoding != null) { request.setCharacterEncoding(characterEncoding); } } // Pass control on to the next filter chain.doFilter(request, response); }
Example 4
Source File: ContextFilter.java From scipio-erp with Apache License 2.0 | 6 votes |
public static void setCharacterEncoding(ServletRequest request) throws UnsupportedEncodingException { // SCIPIO: 2018-05-10: this is the old implementation - it did not check if charset was already set // updating this to the new behavior above instead // String charset = request.getServletContext().getInitParameter("charset"); // if (UtilValidate.isEmpty(charset)) charset = request.getCharacterEncoding(); // if (UtilValidate.isEmpty(charset)) charset = "UTF-8"; // if (Debug.verboseOn()) Debug.logVerbose("The character encoding of the request is: [" + request.getCharacterEncoding() + "]. The character encoding we will use for the request is: [" + charset + "]", module); // // if (!"none".equals(charset)) { // request.setCharacterEncoding(charset); // } if (request.getCharacterEncoding() == null) { String defaultCharacterEncoding = request.getServletContext().getInitParameter("charset"); if (UtilValidate.isEmpty(defaultCharacterEncoding)) { defaultCharacterEncoding = "UTF-8"; } request.setCharacterEncoding(defaultCharacterEncoding); } }
Example 5
Source File: SetCharacterEncodingFilter.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param chain The filter chain we are processing * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding() == null)) { String characterEncoding = selectEncoding(request); if (characterEncoding != null) { request.setCharacterEncoding(characterEncoding); } } // Pass control on to the next filter chain.doFilter(request, response); }
Example 6
Source File: CharsetFilter.java From rice with Educational Community License v2.0 | 6 votes |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain next) throws IOException, ServletException { // Respect the client-specified character encoding // (see HTTP specification section 3.4.1) if (null == request.getCharacterEncoding()) { request.setCharacterEncoding(encoding); } /** * Set the default response content type and encoding */ response.setContentType("text/html; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); next.doFilter(request, response); }
Example 7
Source File: SetCharacterEncodingFilter.java From spacewalk with GNU General Public License v2.0 | 6 votes |
/** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param chain The filter chain we are processing * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used if ((request.getCharacterEncoding() == null)) { String encodingIn = selectEncoding(request); if (encoding != null) { request.setCharacterEncoding(encodingIn); response.setContentType("text/html; charset=" + encodingIn); response.setCharacterEncoding(encodingIn); } } // Pass control on to the next filter chain.doFilter(request, response); }
Example 8
Source File: CommonsUploadMultipartObserver.java From vraptor4 with Apache License 2.0 | 5 votes |
protected String getValue(FileItem item, ServletRequest request) { String encoding = request.getCharacterEncoding(); if (!isNullOrEmpty(encoding)) { try { return item.getString(encoding); } catch (UnsupportedEncodingException e) { logger.debug("Request has an invalid encoding. Ignoring it", e); } } return item.getString(); }
Example 9
Source File: ContentCachedFilter.java From lemon with Apache License 2.0 | 5 votes |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper( (HttpServletRequest) request); String body = new String(requestWrapper.getBody(), request.getCharacterEncoding()); logger.debug("body : {}", body); requestWrapper.setAttribute("x-payload", body); chain.doFilter(requestWrapper, response); }
Example 10
Source File: ViewerFilter.java From birt with Eclipse Public License 1.0 | 5 votes |
public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException { if ( request.getCharacterEncoding( ) == null && encoding != null ) request.setCharacterEncoding( encoding ); // for >= 9.3.x jetty needs this property to change request encoding, // this might change for future versions request.setAttribute("org.eclipse.jetty.server.Request.queryEncoding", encoding); chain.doFilter( request, response ); }
Example 11
Source File: BirtSoapMessageDispatcherServlet.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @see javax.servlet.http.HttpServlet#service(javax.servlet.ServletRequest, * javax.servlet.ServletResponse) */ public void service( ServletRequest req, ServletResponse res ) throws ServletException, IOException { // TODO: since eclipse Jetty doesn't support filter, set it here for // workaround if ( req.getCharacterEncoding( ) == null ) req.setCharacterEncoding( IBirtConstants.DEFAULT_ENCODE ); // workaround for Jetty req.setAttribute( "ServletPath", ((HttpServletRequest)req).getServletPath( ) ); //$NON-NLS-1$ super.service( req, res ); }
Example 12
Source File: BaseReportEngineServlet.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @see javax.servlet.http.HttpServlet#service(javax.servlet.ServletRequest, * javax.servlet.ServletResponse) */ public void service( ServletRequest req, ServletResponse res ) throws ServletException, IOException { // TODO: since eclipse Jetty doesn't support filter, set it here for // workaround if ( req.getCharacterEncoding( ) == null ) req.setCharacterEncoding( IBirtConstants.DEFAULT_ENCODE ); // workaround for Jetty req.setAttribute( "ServletPath", ((HttpServletRequest)req).getServletPath( ) ); //$NON-NLS-1$ super.service( req, res ); }
Example 13
Source File: ServletRequestCharacterEncodingAttribute.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if (context != null) { ServletRequest req = context.getServletRequest(); return req.getCharacterEncoding(); } return null; }
Example 14
Source File: Filter1Encoding.java From boubei-tss with Apache License 2.0 | 5 votes |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if ( request.getCharacterEncoding() == null ) { request.setCharacterEncoding(this.encoding); } HttpServletResponse hsr = (HttpServletResponse) response; hsr.setHeader("Cache-Control", "No-Cache"); chain.doFilter(request, response); }
Example 15
Source File: MultipartToBase64ConverterServletRequest.java From AuTe-Framework with Apache License 2.0 | 5 votes |
private void initialize(){ if (rawData != null) { return; } ServletRequest request = super.getRequest(); try { rawData = readBytes(request.getInputStream()); String encoding = request.getCharacterEncoding(); if (encoding == null) { encoding = StandardCharsets.UTF_8.name(); } params = new MultiMap(); List<FileItem> fileItems = settingsLoadAndParseRequest(); long sum = 0; ConvertedRequestBody convertedRequestBody = new ConvertedRequestBody(request, configProperties.isBoundaryStaticEnabled()); for (FileItem fileItem : fileItems){ if (fileItem.isFormField()){ this.params.add(fileItem.getFieldName(), fileItem.getString(encoding)); log.info(">>>> " + fileItem); } else { this.params.add(fileItem.getFieldName(), fileItem); log.info(">>>> " + fileItem); } sum += fileItem.getSize(); String partBody = buildPartMultipartRequest(fileItem); if(!partBody.isEmpty()) { convertedRequestBody.getAllDataBody().append(partBody); } } processEvalField(fileItems, convertedRequestBody, sum); } catch (Exception ex){ ex.printStackTrace(); } }
Example 16
Source File: ServletRequestCharacterEncodingAttribute.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if (context != null) { ServletRequest req = context.getServletRequest(); return req.getCharacterEncoding(); } return null; }
Example 17
Source File: SetCharacterEncodingFilter.java From ralasafe with MIT License | 3 votes |
/** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * * @param request * The servlet request we are processing * @param result * The servlet response we are creating * @param chain * The filter chain we are processing * * @exception IOException * if an input/output error occurs * @exception ServletException * if a servlet error occurs */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding() == null)) { String encoding = selectEncoding(request); if (encoding != null) request.setCharacterEncoding(encoding); } // Pass control on to the next filter chain.doFilter(request, response); }