How to make a string contain validation in EL
The application is executed using the Struts 1.2 framework. I want to get the hostname of the request header in the jsp file and define the browser reading the value user-agent
from the header.
Below is the code I wrote using scripts:
String userAgent = request.getHeader("user-Agent");
if(userAgent.contains("Chrome")){
userAgent = "Chrome";
}else if(userAgent.contains("Android")){
userAgent = "Android";
}
And the code works fine. But I want to avoid scripting because it has some vulnerable cross-site scripting issues. Hence, in order to do the same in EL, I can get the title using this:
Host is: ${header["user-agent"]}
But I'm not sure how to do the validation contains
in EL.
This application runs on the Struts 1.2 Framework, if the framework provides a better way to read the header value in the JSP, please also let me know. Otherwise EL is fine too.
+3
source to share