Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How make struts2 see my properties file

Hi I have this project structure

enter image description here

and in my index.jsp I have this code:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
  <head>
    <title>
        <s:text name="index.title" />
    </title>
  </head>
  <body>
    <s:form action="Login">
        <s:textfield key="index.login" name="login" />
        <s:password key="index.password" name="password" />
        <s:submit/>
    </s:form>
  </body>
</html>

my content.property file looks like this:

index.hello = Hello user./n/r Please login
index.login = Login
index.password = Password
index.title = Login Page

and when i start the project, struts2 is not getting info from my property file. please tell me what i made wrong I can't find anything helpful on the internet help me please thanks =)

like image 360
Aleksei Bulgak Avatar asked Aug 31 '12 11:08

Aleksei Bulgak


3 Answers

Your properties file needs to be in the your classes directory under WEB-INF or a sub-directory of classes directory.

Let's assume that you have this structure .../Web-INF/classes/property/content.properties, you will need to do this in your struts.xml

<constant name="struts.custom.i18n.resources" value="property.content" />

like image 188
Uchenna Nwanyanwu Avatar answered Sep 19 '22 08:09

Uchenna Nwanyanwu


First rename your content.properties to global_en.properties. Later put it in src folder

like image 40
Alberto Avatar answered Sep 19 '22 08:09

Alberto


You have done all things OK but you have not kept the property file name as of the Action name . The name should be Login.property.

Also please make sure that the property file must be in the same package as of the Action against it is being created.

Please refer the following link for details:

http://struts.apache.org/release/2.2.x/docs/message-resource-files.html

Thanks, Shahid Saeed Khan

like image 42
user2761026 Avatar answered Sep 21 '22 08:09

user2761026