Struts 2 The text tags - Apache Struts 2

what are the text tags in Struts 2? How it is used in Struts 2?

The text tag itself indicates the text messages. It is a generic tag that is used to render a I18n text message. Following are the three steps to be used:
  • The message that is to be sent must be in a resource bundle specifying with the same name as the action that it is associated with. In practice this means that you should create a properties file in the same package as your Java class with the same name as your class, but with .properties extension.
  • If the message name is not found, then the body of the tag will be used as default message.
  • If body is not used, then the name of the message will be used.
Let us check the following example to understand the usage of text tag:

Create action classes

Create views

Let us have HelloWorld.jsp with the following content:

Configuration Files

Let us create a property file with the same name as of your action class package name. So in this case we will create
HelloWorldAction.propertiesfile and keep in the class path:
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:

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

Apache Struts 2 Topics