- 论坛徽章:
- 0
|
web.xml 配置
?xml version="1.0" encoding="UTF-8"?>
!--
Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
-->
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">
display-name>hello/display-name>
distributable />
filter>
filter-name>struts-cleanup/filter-name>
filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp/filter-class>
/filter>
filter-mapping>
filter-name>struts-cleanup/filter-name>
url-pattern>/*/url-pattern>
/filter-mapping>
filter>
filter-name>struts/filter-name>
filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
/filter-class>
/filter>
filter-mapping>
filter-name>struts/filter-name>
url-pattern>/*/url-pattern>
/filter-mapping>
welcome-file-list>
welcome-file>index.html/welcome-file>
/welcome-file-list>
/web-app>
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="false" />
constant name="struts.action.extension" value="html" />
package name="eicp" namespace="/" extends="struts-default">
action name="index" class="HelloWorld">
result name="sucess">/resource/index.jsp/result>
/action>
/package>
/struts>
HelloWorld 类
public class HelloWorld {
private static final String Message="Hello World";
private static final String SUCCESS = "sucess";
public String getMessage() {
return Message;
}
public String execute ( ) {
return SUCCESS;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
index.jsp 使用的视图文件
%@taglib prefix="s" uri="/struts-tags" %>
?xml version="1.0" encoding="UTF-8" ?>
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
html xmlns="http://www.w3.org/1999/xhtml">
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
title>Insert title here/title>
/head>
body>
s:property value="getMessage()"/>
a href="">index/a>
br/>
/body>
/html>
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8660/showart_467628.html |
|