Why are Bootstrap’s form elements rendered terribly with Struts2-Boostrap-Plugin?

Struts2 uses Themes to generate HTML from Tags: a different theme chosen, a different HTML in output. The default theme is XHTML, that generates <td>, <label> and other stuff around your elements. Usually, I recommend to use the simple theme, that generates almost no additional code, and that would make your code work as-is. Put … Read more

Unable to get Struts2 Hello World to work using Eclipse and Maven

If you follow the tutorial, which is linked to the page Struts 2 Hello World Example, and done everything till p. 7 then you should Run it as is written In Struts2, you can access the action class directly with a suffix of .action. http://localhost:8080/Struts2Example/User/Login.action If you tried to access application as http://localhost:8080/Struts2Example you will … Read more

Passing parameters in URL without query string in Struts 2

It was not possible with plain Struts2 under the 2.1+. As a workaround you can do this with UrlRewriter filter. From Struts2 2.1+ with the help of wildcards you can use something like host/ActionNmae/param1-123/param2-abc see this post, but not like host/ActionNmae/123/abc/. The difference is that in the second case there’s no parameter names. The workaround … Read more

Whitelist security constraint in web.xml

I would try the following: <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <!– no auth-constraint tag here –> </security-constraint> <security-constraint> <web-resource-collection> <web-resource-name>restricted methods</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint/> </security-constraint> The first security-constraint does not have any auth-constraint, so the GET and POST methods are available to anyone without login. The second restricts other http methods for everybody. (I … Read more

How to integrate Struts 2 with Tiles 3

The solution is to add the required dependencies, load tiles with an appropriate listener and create a custom result type. Fortunately these steps are quite easy, once done you can follow normal tiles 2 examples for a how to define templates. 1) Dependencies (start with basic struts project but in this example I’ll use conventions … Read more

How to do dynamic URL redirects in Struts 2?

Here’s how we do it: In Struts.xml, have a dynamic result such as: <result name=”redirect” type=”redirect”>${url}</result> In the action: private String url; public String getUrl() { return url; } public String execute() { [other stuff to setup your date] url = “/section/document” + date; return “redirect”; } You can actually use this same technology to … Read more