JSP & Servlets
1.0.0
1.0.0
  • Setting up
  • Pre-requisites
  • Servlet Part 1
  • Servlet Part 2
  • Understanding the servlet
  • Servlet XML Configuration
  • POST method and passing parameters
  • Passing more parameters
  • Understanding GET and POST
  • Request, Session and Context Part -1
  • Request , Session and Context Part - 2
  • Understanding init, service and ServletConfig
  • Hello JSP
  • Understanding JSP
  • JSP Page directives
  • HttpServletRequest Path Decoding
  • Scopes in JSP and the PageContext Object
  • Understanding MVC pattern
  • PART -1 Writing an MVC app
  • JSTL
    • For-each
  • CRUD-1
  • Project Work
    • Create a Simple Java Web Application Using Servlet, JSP/JSTL and JDBC/Transaction
  • Locale Filter
  • Action Plan
    • Schedule
    • Hit webservice
Powered by GitBook
On this page

Was this helpful?

Locale Filter

PreviousCreate a Simple Java Web Application Using Servlet, JSP/JSTL and JDBC/TransactionNextSchedule

Last updated 5 years ago

Was this helpful?

package com.gs.ilp.controller;

import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class SimpleServletFilter implements Filter {

	public void init(FilterConfig filterConfig) throws ServletException {
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
			throws IOException, ServletException {

		Locale locale = request.getLocale();

		// FileInputStream fileInputStream = new
		// FileInputStream("messages_en_IN.properties");
		ResourceBundle resourceBundle = ResourceBundle.getBundle("resources/messages", locale);
		System.out.println(locale.getLanguage());
		request.setAttribute("messages", resourceBundle);
		// Set<String> keys= resourceBundle.keySet();
		// for(String key: keys) {
		// Message message = new Message(key, resourceBundle.getString(key));
		// }

		filterChain.doFilter(request, response);
	}

	public void destroy() {
	}
}