> How can I generate the csrf token within the java? > Have you looked at the JSP_Tag_Library? https://www.owasp.org/index.php/CSRFGuard_3_Token_Injection#JSP_Tag_Library I'm not familiar with Struts, but we use the tag library for adding tokens to urls.