Hello Struts2 !
2010-02-02 10:00
169 查看
新建 JAVA WEB 项目 StrutsTest
拷贝 example Apps 里面的 struts.xml 到 MyEclipse StrutsTest 项目里面的 src 目录下,拷贝 example Apps 里面的 JAR 包到 WebRoot/WEB-INF/lib 目录下,打开 MyEclipse StrutsTest 项目里面的 WebRoot/WEB-INF 目录下的 web.xml ,参照 example Apps 里面的 web.xml 添加 filter 代码:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
标签里面的 /* 一般不需要改动 ( /* 是指对全部地址进行过滤 ),或者是改动到这个值。
在 struts.xml 的 标签中插入如下代码:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
在通过一下代码设定开发者模式:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
重启服务器后,在浏览器访问 localhost/StrutsTest/hello 即可访问 index.jsp。
访问原理分析:
当我们在浏览器中输入 localhost/StrutsTest/hello ,Tomcat 会根据此 URL 读取 StructsTest 目录中的 web.xml ,此 web.xml 里面配置了过滤器 filter ,此过滤器将所有地址访问都转给了 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter ,这个 StrutsPrepareAndExecuteFilter 类分析 URL ,得到 namespace 为 / ,然后定位到 namespace 为 / 的 package ( 当 namespace 为空的时候能匹配所有 action ),调用里面的 action ,配对到 index.jsp。
有 Hello World 情节的童鞋,可以在修改 index.jsp 内容为 Hello World,或者 Hello Struts2..
拷贝 example Apps 里面的 struts.xml 到 MyEclipse StrutsTest 项目里面的 src 目录下,拷贝 example Apps 里面的 JAR 包到 WebRoot/WEB-INF/lib 目录下,打开 MyEclipse StrutsTest 项目里面的 WebRoot/WEB-INF 目录下的 web.xml ,参照 example Apps 里面的 web.xml 添加 filter 代码:
1:
2:struts2
3:
4: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
5:
6:
7:
8:struts2
9:/*
10:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
标签里面的 /* 一般不需要改动 ( /* 是指对全部地址进行过滤 ),或者是改动到这个值。
在 struts.xml 的 标签中插入如下代码:
1:
2:
3:
4: /index.jsp
5:
6:
7:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
在通过一下代码设定开发者模式:
1:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
重启服务器后,在浏览器访问 localhost/StrutsTest/hello 即可访问 index.jsp。
访问原理分析:
当我们在浏览器中输入 localhost/StrutsTest/hello ,Tomcat 会根据此 URL 读取 StructsTest 目录中的 web.xml ,此 web.xml 里面配置了过滤器 filter ,此过滤器将所有地址访问都转给了 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter ,这个 StrutsPrepareAndExecuteFilter 类分析 URL ,得到 namespace 为 / ,然后定位到 namespace 为 / 的 package ( 当 namespace 为空的时候能匹配所有 action ),调用里面的 action ,配对到 index.jsp。
有 Hello World 情节的童鞋,可以在修改 index.jsp 内容为 Hello World,或者 Hello Struts2..
相关文章推荐
- Struts2HelloWorldExample
- 非IDE方式手动配置struts2环境之hello_world
- Struts2.0报错HTTP Status 404 - /Struts2_HelloWorld/HelloWorld
- Struts2平凡之路(二)Hello Struts2!
- Struts2's HelloWorld
- Struts2 快速入门(hello struts2 简单示例,配置开发模式,导入struts源码,设置struts.xml源码提示)
- How To Create Struts 2 helloWorld on Eclipse(新建struts2项目)
- JavaEE之Struts2入门-----1:Hello,World+name
- Eclipse使用Maven创建Struts2工程之Helloworld
- struts2学习之HelloWorld
- Struts2 官方教程之Hello World Using Struts 2(四)
- struts2入门-第一个例子==》第一个struts2实例——HelloWorld==》Struts2.0搭建和简单实例==>写一个Steuts2的经典入门案例,做了一个登陆程序作为入门例子
- struts2异常 no action named HelloWorld .......
- Struts2系列之HelloAction
- struts2环境搭建helloword
- struts2--Hello struts2练习
- SSH 整合 spring struts2整合 hello 实例教程 火推
- struts2 的第一个程序hello struts2
- struts2 第一个程序 以及错误There is no Action mapped for action name hello 解决
- Struts2 Hello,Wold