I've Struts 1 action which sends a recommendation mail from a webpage but it doesn't read the messageresource properly. I get the output in portuguese no which language I set it to.
I've in my struts-config.xml
<controller locale="false" />
and this is my action:
/*
* RecommendAction.java
*
* Created on den 8 maj 2006, 16:04
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package marketleader;
import org.apache.struts.action.*;
import org.apache.log4j.*;
import org.apache.struts.util.*;
import marketleader.util.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
public class RecommendAction extends Action {
Logger log = Logger.getLogger(this.getClass());
@Override
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
setLocale(request, new Locale(Constants.LANGUAGE, Constants.COUNTRY));
RecommendForm myForm = (RecommendForm) form;
String smtpServer = Constants.SMTP_SERVER;
String subject = "";
String body = "";
String id = request.getParameter("id");
Connection conn = null;
try {
conn = DBSettings.getConnection();
String sql = "select subject from classifieds where id=?";
PreparedStatement st = conn.prepareStatement(sql);
st.setString(1, id);
ResultSet rs = st.executeQuery();
if (rs.next()) {
subject = rs.getString("subject");
}
} catch (Exception sqlEx) {
log.error("SQLException", sqlEx);
//TODO forward to error page
} finally {
try {
conn.close();
} catch (SQLException sqlEx) {
//TODO forward to error page
log.error("SQLException", sqlEx);
}
}
//setLocale(request, new Locale(Constants.LANGUAGE, Constants.COUNTRY));
//setLocale(request, new Locale("sv", "SE"));
MessageResources messageResources = getResources(request);
log.info("messageresources config"+messageResources.getConfig());
setLocale(request, new Locale(Constants.LANGUAGE, Constants.COUNTRY));
String mess = "(" + messageResources.getMessage("this.email") + " <a href=\"http://" + request.getServerName() + "\">" + request.getServerName() + "</a> " + messageResources.getMessage("not.to.be.answered");
mess = mess + "<br><br>" + messageResources.getMessage("your.friend") + " <b>" + myForm.getName() + "</b> " + messageResources.getMessage("recommends.the.ad") + " <a href=\"http://" + request.getServerName() + "\">" + request.getServerName() + "</a>.";
mess = mess + "<br><br>" + messageResources.getMessage("click.link");
mess = mess + "<br><br><a href=\"http://" + request.getServerName() + "/vi/" + id + ".htm" + "\">http://" + request.getServerName() + "/vi/" + id + ".htm</a>";
mess = mess + "<br><br><b>" + messageResources.getMessage("sent.by.system") + " " + request.getServerName().replaceAll("www.", "") + ".";
mess = mess + "<br><br><a href=\"http://" + request.getServerName().replaceAll("www.", "") + "\">" + request.getServerName().replaceAll("www.", "") + "</a> - " + messageResources.getMessage("buy.and.sell.site");
log.info("sending recommendation mail");
//new MarketMail(Constants.SMTP_SERVER, myForm.getEmail(), "no-reply@" + request.getServerName(), "Rekommendation: " + subject, mess, request.getServerName());
log.info("email:" + myForm.getEmail());
new MarketMail(Constants.SMTP_SERVER, myForm.getEmail(), "info@" + request.getServerName().replaceAll("www.", ""), subject, mess, request.getServerName().replaceAll("www.", ""));
request.setAttribute("message", "<p>" + messageResources.getMessage("congratulations") + " <b>" + myForm.getName() + "</b><br><br>" + messageResources.getMessage("recommendation.was.sent")+"<br><br>" + messageResources.getMessage("thanks.for.using.our.services")+"<br><br>");
return mapping.findForward("success");
}
}
Neither setting the locale in the code nor from a properties file works. On Linux that is. On MS-windows results are working well. What could be the bug?
Thank you for your help.
Niklas