0

I have an variable written in Spring EL that I want to url decode, can I just drop in a piece of code between the curly brackets or does the parsing have to be done in the controller?

<form:hidden id="pass" path="password" value="${param.password}" htmlEscape="true" />

For example, can I do something like this:

<form:hidden id="pass" path="password" value="${URLDecoder.decode(param.password, "UTF-8")}" htmlEscape="true" />

The issue is that some passwords have special characters and are url encoded.

llanato
  • 2,508
  • 6
  • 37
  • 59

1 Answers1

1

Try using spring:eval to execute the static method call and set the value. References:

Spring Eval Reference

Spring Eval Example 1

Update:

Spring Eval Example 2

Update: Tried with what you were looking for and here is what I have:

Controller:

@RequestMapping("/testStaticCall")
    public String testStaticCall(ModelMap map) {
        map.addAttribute("password", "1234%23");
        return "testStaticCallJsp";
    }

JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
    <spring:eval expression="T(java.net.URLDecoder).decode(password)" var="decodedPassword"></spring:eval>
    <form:input id="pass" path="password" value="${decodedPassword}" htmlEscape="true" />
</body>
</html>

Output:

enter image description here

Community
  • 1
  • 1
James Jithin
  • 10,183
  • 5
  • 36
  • 51