Moving from JSP to Thymeleaf

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Moving from JSP to Thymeleaf

rajnish
I'm trying to integrate a payment gateway with my instance of broadleaf eCommerce site, the payment gateway company have given a jsp file that i need to use in order to be able to post on their API.
I can no not use the JSP as is, as "<@% " is not recognized by thymeleaf. and it thows error as following:
org.thymeleaf.exceptions.TemplateInputException: Exception parsing document: template="checkout/posttozaakpay", line 1 - column 2 (layout/checkoutLayout:16)

I tried googling but get nothing... hence the post.

Any help is greatly appreciated...


Here is the posttozaakpay.jsp, i need to convert to thymeleaf:

<%@page language="java" import="com.zaakpay.api.lib.*"%>
<%@page language="java" import="java.util.Enumeration"%>
<%
                        // Please insert your own secret key here
                        String secretKey = "b837d42bf9bd4c0f56a2026b0";
                        String allParamValue = ChecksumCalculator.getAllNotEmptyParamValue(request).trim();
                        System.out.println("allParamValue : " + allParamValue );
                        System.out.println("secretKey : " + secretKey );
                        String checksum = ChecksumCalculator.calculateChecksum(secretKey, allParamValue);
                        request.setAttribute("checksum", checksum);
%>
                       
                       

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zaakpay</title>
<script type="text/javascript"> function submitForm(){ var form = document.forms[0]; form.submit(); } </script></head>
<body onload="javascript:submitForm()">
<center>
                                                       
       
Do Not Refresh or Press Back <br/> Redirecting to Zaakpay
                        <form action="https://api.zaakpay.com/transact" method="post">
                        <%
                                Enumeration paramNames = request.getParameterNames();
                                while (paramNames.hasMoreElements()) {
                                        String param = (String)paramNames.nextElement();
                                        if ("returnUrl".equals(param)) {
                        %>
                                                <input type="hidden" name="<%=param%>" value="<%=ParamSanitizer.SanitizeURLParam(request.getParameter(param))%>" />
                        <%
                                        } else {
                        %>
                                                <input type="hidden" name="<%=param%>" value="<%=ParamSanitizer.sanitizeParam(request.getParameter(param))%>" />
                        <%
                                        }
                                }
                        %>
                                <input type="hidden" name="checksum" value="<%=request.getAttribute("checksum")%>" />
                        </form>
               

</center>       
</body>
</html>
                       
Reply | Threaded
Open this post in threaded view
|

Re: Moving from JSP to Thymeleaf

Zemi
Administrator
These are the basics of Thymeleaf, so I recommend you to read a bit the documentation first.

First, you have to put the code

                        String secretKey = "b837d42bf9bd4c0f56a2026b0";
                        String allParamValue = ChecksumCalculator.getAllNotEmptyParamValue(request).trim();
                        String checksum = ChecksumCalculator.calculateChecksum(secretKey, allParamValue);
                        request.setAttribute("checksum", checksum);

into your controller, and then, the rest of the code into your template.

Instead of the while you have to use th:each, instead the name="<%=param%> you have to use th:name="${param}" and so on.
Reply | Threaded
Open this post in threaded view
|

Re: Moving from JSP to Thymeleaf

rajnish
Many Thanks Zemi,

I went through the tutorials and with some basic understanding could move all the JAVA code from jsp to controller and migrate the jsp file thymeleaf and could get my page populating!

Thanks Again for quick help.

Cheers,
Rajnish