Posted on 2010-12-14 18:07
viery 阅读(2680)
评论(1) 编辑 收藏 所属分类:
JavaEE
1.搭建环境
将项目引入相关jar包:struts1.2 ;jstl,配置struts-config.xml文件
2.根据struts-config.xml中资源文件配置标签的basename,配置中文、英文(如果你会火星文也可以)的资源文件。总的说来,国际化工作是量大难点少。
3.写好相关action和jsp文件。
下面是相关配置文件:
struts-config.xml:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="stepform" type="org.vle.order.StepActionForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/step"
type="org.vle.order.StepAction"
name="stepform"
parameter="stuts"
scope="session"
>
<forward name="gos1" path="/step1.jsp"/>
<forward name="gos2" path="/step2.jsp"/>
<forward name="gos3" path="/step3.jsp"/>
<forward name="show" path="/show.jsp"/>
<forward name="ok" path="/suc.jsp"/>
</action>
</action-mappings>
<message-resources parameter="MessageBundle" />
</struts-config>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
再写中文资源文件的时候,虽然myeclipse有的版本也许集成了转unicode功能,但是最好通过命令行将资源文件编译成unicode,以免出现乱码。
index.begin=\u5f00\u59cb \u4e3a\u4e2d\u56fd\u7684\u7528\u6237
step.user=\u7528\u6237
step.next=\u4e0b\u4e00\u6b65
step.prod=\u4ea7\u54c1
step.add=\u5730\u5740
step.submit=\u63d0\u4ea4
step.suc=\u6210\u529f
en:
index.begin=begin for USA
step.user=user
step.next=next
step.prod=productor
step.add=address
step.submit=submit
step.suc=sucessful book