Spring Controller request parameter wrong encoding in one instance of Tomcat but not the others - spring

I have a Spring MVC application which works fine in eclipse (local tomcat instance) and in a test environment where tomcat is installed as a service. But when I deploy the application in production the request parameters are not parsed correctly (Greek characters).
My server.xml configuration file in production (and in both local and test envirnonments) has the URIEncoding="utf-8" attribute on all connector elements.
I have set the CharacterEncodingFilter in web.xml.
My Jsp pages have all the
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
and
<%#page contentType="text/html" pageEncoding="UTF-8"%>
What else could be different between these Tomcat instances?
The only thing I can think off is the regional settings on windows but I hope this does not affect this?

Related

How to fix this springboot ErrorPageFilter error?

It's a simple web application use external tomcat-9.0.56 and spring 5.3, springboot 2.5.5 and up, which works on windows 10 but not on ubuntu 18. It always display 404 because of the ErrorFilterPage.
The tomcat used Context to point to the folder where the webapp was located at, also virtual host in apache 000-default.conf
I've tried set setRegisterErrorPageFilter(false); or in the application.properties as well as inject #Bean FilterRegistrationBean disableSpringBootErrorFilter with/without return new ErrorPageFilter(); in #Bean public ErrorPageFilter errorPageFilter(), no success.
I feel despair at such a framework that can not deploy to Ubuntu with delays and disappointment that cause me a lot.
It's just a simple hello: http://localhost:8080/home:
https://drive.google.com/file/d/1BiJ4-E0nPjuh1YxREpOcwN4AlzdSe3Pu/view?usp=sharing
How to fix it?!
There's a typo in your application.properties file where you have configured spring.mvc.view.prefix. The value has a trailing space. It is /WEB-INF/views/ and should be /WEB-INF/views/. With this change in place, the /hello endpoint works:
$ curl localhost:8080/hello
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>SAMPLE</title>
</head>
<body>
HELLO SPRING!
</body>
</html>%
Spring Boot intentionally does not trim whitespace from property values as there's no way for it to know whether or not the whitespace is intentional.

send arabic data in spring mvc form

i have a spring form where i need to send some data in arabic so
i set the page encoding and the content type to UTF-8 like this :
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
...
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
when i display the data in the controller i get something like this ?¨???¦?³?±???§
i'm using spring 4 along with spring security, i don't know if this can be be the cause, but can it be the csrf added by spring security ?
thanks in advance

Spring taglib in uiBinder xml-file

How can I put my taglib prefix correctly in my name.ui.xml file, is it even possible ?
In an html/jsp file it normally would work with
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
But thats not the case with uiBinder xml files. Is there a way or an alternative ? I'm trying to ensure multilingualism in my application. Thx for any help :)
You do understand that JSP is processed by your server, and UiBinder is processed by the GWT compiler to produce JS for the browser (client), right?
If you want to internationalize your GWT application, there are tools for that: http://www.gwtproject.org/doc/latest/doc/latest/DevGuideI18n.html

Spring tags and facelets

Can I use Spring tags with facelets? I have one JSP page, and there is a directive:
<%# taglib prefix="s" uri="http://www.springframework.org/tags"%>
Then I can insert the tag <s:theme code='css' /> (I'm using theme resolver.) Now I need to use theme resolver in another project using facelets instead JSP. There is a namespace declaration instead the JSP directive, isn't?
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:em="http://java.sun.com/jsf/composite/emcomp"
xmlns:st="http://www.springframework.org/tags">
But in Eclipse the namespace is labeled with the warning marker and on server it does not work, because the tag library is missing, althought I have put the library Spring Web MVC in the lib directory of Eclipse Internal Glassfish server. The JAR really contains META-INF/spring.tld.
I'm unable to find, what's wrong.
No, unfortunately you cannot. Spring tags are based on a JSP taglib. Facelet taglibs are different from JSP taglibs. The reason you can use the old-fashioned jsp core tags (c:forEach etc) in facelets is because they have been ported to facelet taglibs. AFAIK, there has not been any port done yet of the Spring JSP taglib to a facelet taglib.

Jasper in Jetty 6 throws exception for JSTL tag

I'm trying to run an application in jetty that runs fine in Tomcat 5.5. The app uses servlet 2.4 and JSP 2.0.
Jetty/Jasper is throwing this exception:
org.apache.jasper.JasperException: /WEB-INF/tiles/layout/main.jsp(85,55) PWC6340: According to the TLD, rtexprvalue is true, and deferred-value is specified for the attribute items of the tag handler org.apache.taglibs.standard.tag.rt.core.ForTokensTag, but the argument for the setter method is not a java.lang.Object
One odd thing, I can't find the TLD anywhere. It seems to be obtaining it by magic that I don't understand. Is it possibly getting a wrong TLD?
It's also hard to tell from where it's loading org.apache.taglibs.standard.tag.rt.core.ForTokensTag. Eclipse doesn't find it in the load path of the project.
Any hints welcome ...
Jetty includes their own JSTL library and there is no need to include jakrta taglib's standard and core jars.
If you do put jakartat taglib's jars into your web application then there is a conflict in the forTokens tag that causes this error while other tags work well. I suggest either remove the jakarta taglib implementation from your web app and rely on Jetty's, or stop using forTokens.
#Guss is correct, the only way out seems to be to avoid the use of c:forTokens.
example alternative to c:forTokens using c:forEach:
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%#taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:forTokens items="${input}" delims="," var="i">
<!-- do stuff with ${i} -->
</c:forTokens>
<c:forEach items="${fn:split(input,',')}" var="i">
<!-- do stuff with ${i} -->
</c:forEach>

Resources