Multiple message resource property file in Struts

Recently I came up with a requirement where in we have to display messages from multiple bundle resource (message resource) property files in Struts using <bean:message>. Following are the steps for the same:
  1. Make an entry of message resource file name in struts-config.xml file.
  2. Once this is done, the message resource file can be accessed by using the key (in this case we have myResource & myOtherResource). The key should be used in <bean:message> tag in jsp to display perticular message from the resource property file. bundle=”” attribute of <bean:message> is used to identify the perticular property file.
    <bean:message bundle="myResource" key="somekey.in.myresource" /> <bean:message bundle="myOtherResource" key="somekey.in.myotherresource"/>
    Code language: HTML, XML (xml)

View Comments

  • what is switch action in Struts.can you explain with an example.Can you explain ForwardAction,IncludeAction,DispatchAction,LookupDispatchAction,SwitchAction with a detailed example.

  • what is use use of redirect attribute and how do we can achieve sendRediect in struts?
    please send me the code.

    Thanks in advance.

  • On using at jsp m geting this error

    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:489)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
    org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    hr.fts.global.SessionCheckFilter.doFilter(SessionCheckFilter.java:112)

    root cause

    javax.servlet.ServletException: Cannot find message resources under key myOtherResource
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
    org.apache.jsp.hr.FTSG5.transactions.FTSLetterFileListing_jsp._jspService(FTSLetterFileListing_jsp.java:212)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
    org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    hr.fts.global.SessionCheckFilter.doFilter(SessionCheckFilter.java:112)

Share
Published by
Viral Patel
Tags: How-To Java Struts

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

4 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

4 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

4 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

4 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

5 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago