实验三(Struts的国际化).docVIP

  • 30
  • 0
  • 约3.83千字
  • 约 6页
  • 2017-02-05 发布于北京
  • 举报
实验三(Struts的国际化)

班级: 计算机12-2 学号: 12034480233 姓名: 唐大义 成绩: 实验三:Struts2的国际化 实验目标: 掌握Struts2国际化技术的使用 实验内容: 使用struts2标签库编写一个用户注册的JSP页面,包含有姓名、昵称、性别和爱好四个字段,然后把这四个字段的标题及选项内容改为支持国际化显示。 实验步骤: 1、创建web工程; 2、添加Struts2框架所必须的jar包; 3、添加Struts2的核心配置文件struts.xml; 4、配置web.xml文件; 5、编写register.jsp,页面的功能为用户注册,如下图所示,要求只能够使用struts标签库来实现;在jsp中引入strusts标签库的方法为: “%@taglib uri=/struts-tags prefix=s%” 6、部署运行,观察页面效果; 7、建立国际化资源文件messages_en_US.properties及messages_zh_CN.properties; 8、把register.jsp中的中文全部改为支持国际化显示; 9、在struts.xml中配置国际化资源文件所在的位置,配置的常量为“struts.custom.i18n.resources”; 10、部署运行项目进行测试国际化功能的效果。 提示:性别和爱好中的选项需要编写Action从后台获取国际化资源。 实验报告: 提交相关程序代码(action类程序、web.xml、struts.xml、JSP、国际化资源文件)和页面效果. action类: package com.tdy.action; import java.util.HashMap; import java.util.Map; import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport { private MapString, String sexs = new HashMapString, String(); private MapString, String hobbies = new HashMapString, String(); public MapString, String getSexs() { return sexs; } public void setSexs(MapString, String sexs) { this.sexs = sexs; } public MapString, String getHobbies() { return hobbies; } public void setHobbies(MapString, String hobbies) { this.hobbies = hobbies; } public String login(){ String male = getText(male); String female = getText(female); sexs.put(f, female); sexs.put(m, male); String dancing = getText(dancing); String football = getText(football); String other = getText(other); hobbies.put(d, dancing); hobbies.put(fb, football); hobbies.put(o, other); return SUCCESS;}} Web.xml页面: ?xml version=1.0 encoding=UTF-8? web-app version=2.5 xmlns=/xml/ns/javaee xmlns:xsi=/2001/XMLSchema-instance xsi:schemaLocation=/xml/ns/javaee /xml/ns/javaee/web-app_2_5.xsd welcome-file-list welcome-fileindex.jsp/welcome-file /welcome-file-list filter filter-namestruts2/filter-name filter-classorg.apache.struts2.dispatcher.FilterDispatcher/filter-class /filter filter-mappin

文档评论(0)

1亿VIP精品文档

相关文档