加粗样式
效果图
1.Employee.java 封装
package com.oumyye.action;
import com.opensymphony.xwork2.ActionSupport;
public class Employee extends ActionSupport{
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getpassword() {
return password;
}
public void setpassword(String password) {
this.password = password;
}
public String execute() {
return SUCCESS;
}
}
2.Locale.java 文件
接受数据
package com.oumyye.action;
import com.opensymphony.xwork2.ActionSupport;
public class Locale extends ActionSupport{
public String execute()
{
return SUCCESS;
}
}
3 中英文的转换
4 struts.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<!-- 扫描资源目录下以global开头的文件 -->
<constant name="struts.custom.i18n.resources" value="global" />
<!-- 常量配置资源文件命名-->
<package name="helloworld" extends="struts-default" namespace="/">
<action name="empinfo"
class="com.oumyye.action.Employee"
method="execute">
<result name="input">/index.jsp</result>
<result name="success">/success.jsp</result>
</action>
<action name="locale"
class="com.oumyye.action.Locale"
method="execute">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
5.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
- index.jsp文件
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body >
<h1><s:text name="global.heading"/></h1>
<s:url id="indexZH" namespace="/" action="locale" >
<s:param name="request_locale" >zh_CN</s:param>
</s:url>
<s:url id="indexFR" namespace="/" action="locale" >
<s:param name="request_locale" >en_US</s:param>
</s:url>
<!-- href ="locale?request_locale=zh" -->
<button><s:a href="%{indexZH}" >中文</s:a></button>
<button><s:a href="%{indexFR}" >English</s:a></button>
<s:form action="empinfo" method="post" namespace="/">
<s:textfield name="name" key="global.name" size="20" />
<s:textfield name="password" key="global.password" size="20" />
<s:submit name="submit" key="global.submit" />
</s:form>
</body>
</html>
页面的布置
7.scuccess.jsp文件
主要是接受登录成功的数据
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Success</title>
</head>
<body>
恭喜你,提交成功!
</body>
</html>