java - JSP resourceBundle -


i have no problem loading , using properties file jsp files located in root of website (using resourcebundle class) when try load same properties file jsp located in directory fails , says resource can not found!

code of page located in directory

<%@page import="org.apache.log4j.logger"%> <%@page import="com.persiangulfcup.utility.logutils"%> <%@page import="java.util.resourcebundle"%> <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <%   logger logger = logutils.getlogger("page/contact");   resourcebundle lbls = null;   resourcebundle msgs = null;   try {     lbls = resourcebundle.getbundle("labels");     msgs = resourcebundle.getbundle("messages");   } catch (exception ex) {     logger.fatal(ex);   } %> <div class="form">   <div style="text-align: left; font: normal bold 14px arial; cursor: pointer" onclick="contactbox.hide();">x</div>   <div style="padding-bottom: 10px;font-size: 14px; text-align: center"><%=msgs.getstring("contactheader")%></div>   <form id="frmcontact" onsubmit="try {sendcontact();} catch (e) {console.log(e)} return false;">     <table class="form">       <tr>         <td class="caption"><%=lbls.getstring("name")%>: </td>         <td class="data">           <input id="txtname" type="text" name="txtname"/>         </td>       </tr>       <tr>         <td class="caption"><%=lbls.getstring("email")%>: </td>         <td class="data">           <input id="txtemail" type="text" name="txtemail"/>         </td>       </tr>       <tr>         <td class="caption"><%=lbls.getstring("subject")%>: </td>         <td class="data">           <input id="txtsubject" type="text" name="txtsubject"/>         </td>       </tr>       <tr>         <td class="caption"><%=lbls.getstring("message")%>: </td>         <td class="data">           <textarea id="txtmessage" name="txtmessage"></textarea>         </td>       </tr>       <tr>         <td class="button" colspan="2"><input type="submit" value="<%=lbls.getstring("send")%>"/></td>               </tr>       <tr>         <td style="text-align: center" colspan="2" id="brdcontact"></td>               </tr>     </table>   </form> </div> 

this because didn't respect golden rule: don't put in default package. resource bundle loaded class, classpath. has qualified name, must used load it. , it's not possible use class in default package class not in default package.

so, put resource bundle in appropriate package (example : com.persiangulfcup.foo.bar), , load them : resourcebundle.getbundle("com.persiangulfcup.foo.bar.labels").

that said, using scriptlets inside jsps bad practice. should use the jstl, has fmt library allowing use resource bundles, format messages, etc.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -