I have this Web Application in JSP running on JBoss Application Server. I am using Servlets for friendly urls. I'm sending search parameters through my JSP's and Servlets. I am using a form with a text box, the Servlet
The first Servlet uses request.getParameter()
to get the text, and sends it to another Servlet with response.sendRedirect
(masking the URL to something "friendly"). This final Servlet uses request.getRequestDispatcher().forward()
to send the parameters to the JSP in the "ugly" way: searchResults.jsp?searchParameters=Parameters
.
Now, when the Search Results page is displayed, the URL displays the correct search term with "friendly url". Example: http://site.com/search/My-Search-Query
even when using special characters like: http://site.com/search/Busqué-tildes-y-e?ies
. But when I try to use that search term in my JSP, the special characters are not displayed correctly.
The whole system uses i18n, and we've had no problems with special characters so far. But when the information is sent through the form (say from index.jsp to searchResults.jsp) special characters are not correctly displayed:
á - ??
é - ??
í - ?
ó - ?3
ú - ?o
? - ?±
The whole code base is supposed to be in UTF-8, but apparently I'm missing something when passing the parameters. As I said, they are correctly displayed in the URL, but not inside the JSP.
I was thinking of converting those ??
manually, but I guess there's a better way to do it correctly, using the correct encoding. Besides, there can be new characters later which I may not be aware of right now (French, Spanish, etc.)
Just in case, I'll let you know I have these lines on each JSP:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
EDIT
Thanks for your answers. I tried a few things, but nothing has fixed the problem.
Here's what I've done:
I added a ServletRequestListener which sets the session's character encoding to UTF-8, and a Filter for every Http request, which does the same.
As I said, everything in the JSPs is encoded with UTF-8 (see headers in question).
I printed the Servlets' character encoding to the console, which were null by default, set them to UTF-8 like @kgiannakakis and @saua said.
None of these actions fixes the problem. I'm wondering if there's something else wrong with this...
See Question&Answers more detail:
os