Struts 2 The url tags - Apache Struts 2

The url tag is helpful in generating URL strings. The main advantage of this is that you can supply parameters to the tag. Let us go through an example to show the usage of url tag.

Create action classes

Create views

Let us have HelloWorld.jsp with the following content:
Here we are generating a url link to the "login.action". We have given this url a name "myurl". This is because we can reuse this url link in multiple places within the jsp file. We then supply the url with a parameter called user. The parameter value is actually appended to the query string as you can see from the output above.
The URL tag is mainly useful when you want to create a dynamic hyperlink based on a bean's property value.

Configuration Files

Your struts.xml should look like:
Your web.xml should look like:
Right click on the project name and click Export > WAR File to create a War file. Then deploy this WAR in the Tomcat's webapps directory. Finally, start Tomcat server and try to access URL http://localhost:8080/HelloWorldStruts2/hello.action. This will give you following screen:
strutsurltag

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache Struts 2 Topics