Spring javax.servlet.jsp.JspTagException:code';errors.contact.sysadmin.msg';对于区域设置';en#u US';]
我已将邮件资源配置为: tradelc-servlet.xmlSpring javax.servlet.jsp.JspTagException:code';errors.contact.sysadmin.msg';对于区域设置';en#u US';],spring,jsp,spring-mvc,Spring,Jsp,Spring Mvc,我已将邮件资源配置为: tradelc-servlet.xml <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="WEB-INF/classes/resources/application" /> </bean&
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="WEB-INF/classes/resources/application" />
</bean>
请帮助您必须提供basename命名约定(并且),您会发现basename是错误的-您既不应该提供WEB-INF/-部分,也不应该提供参考资料部分 假设您的
ResourceBundle
是一个PropertyResourceBundle
,由两个文件组成
和src/main/resources/application.properties
src/main/resources/application\u en.properties
maven
打包的,并且文件位于目录/WEB-INF/classes/
,那么您的基本名称应该仅仅是应用程序,因为WEB-INF/classes
是类加载器查找其类的地方(类似于它的根目录)
顺便说一句:当属性文件不是XML文件时,不应该将其命名为.XML。您是否真的调用了文件应用程序\u en.properties.xml
?简单的解决方案是在下面添加属性文件
The simple solution, will be to add property file under
"src/main/resource" directory and to access it simply configure "DispatcherServlet-context.xml" file like this
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="name_of_the_resource_file" />
</bean>
“src/main/resource”目录,要访问它,只需像下面这样配置“DispatcherServlet context.xml”文件
假设我的messages.properties
类位于src/main/resources
中,这是一个maven
定义的目录
消息。属性包含如下值:
person.name=Person Name
person.age=Person Age
person.address=Person Address
因此,我在DispatcherServlet配置文件中创建了messageSource
bean,如下所述,使用属性schemaxmlns:p=”http://www.springframework.org/schema/p“
:
我将使用spring标记库获取jsp文件中的属性值,如:
html标记上方的jsp声明:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
正文内容如下:
<form:form commandName="person">
<table>
<tr>
<td><spring:message code="person.name" /></td>
<td><form:input path="personName"/></td>
</tr>
<tr>
<td><spring:message code="person.age" /></td>
<td><form:input path="age"/></td>
</tr>
<tr>
<td><spring:message code="person.address" /></td>
<td><form:input path="address"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Set Person Details"/>
</td>
</tr>
</table>
</form:form>
通过执行这些步骤,我可以肯定,您的javax.servlet.jsp.JspTagException
已经解决了。您是如何构建应用程序的?你是在使用maven还是类似的工具。我假设您的属性(您提到了一个xml)可能位于不正确的路径中。我使用的是maven
。我错误地将其作为xml。在我的项目中,它被指定为.properties文件,只有当我在messageresource中给出application\u en
而不是application
时,它才得到解决。我的资源文件位于src/main/resources/resources/application\u en.properties
中
@vysh是的,捆绑包必须始终至少包含没有语言键的默认属性。添加其他区域设置(_en,_en_US)是可选的。如果我想在basename中提供外部路径:“给定本地驱动器路径”并使用可重新加载的ResourceBundleMessageSource。它没有加载属性。任何建议嘿,但是如果我没有src/main/resources文件夹呢?我的项目是动态Web项目,而不是maven。我把我的属性文件放在/WEB-INF/properties/下,但它给我的错误消息与上面相同。你有什么办法解决这个问题吗?
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages"/>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form commandName="person">
<table>
<tr>
<td><spring:message code="person.name" /></td>
<td><form:input path="personName"/></td>
</tr>
<tr>
<td><spring:message code="person.age" /></td>
<td><form:input path="age"/></td>
</tr>
<tr>
<td><spring:message code="person.address" /></td>
<td><form:input path="address"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Set Person Details"/>
</td>
</tr>
</table>
</form:form>