本人虽然是科班出身,但大学四年没沉下心来好好学点东西,到现在突然发现自己不懂的东西实在是太多了。 从今天开始,决定发奋图强!基于以前的基础,现在开始SSH框架的学习之路,首先从Struts2开始,争取以后每日都能发表自己的学习感悟,与广大好友共同学习进步。 今天的Struts2学习就简单的介绍下HelloWorld的实现! 首先在网上下载Struts2框架,本人下载的是Struts-2.3.20版本,下好之后打开文件夹,看见其目录结构为:![Struts-2.3.20](https://img-blog.csdn.net/20150811224250281) 之后在myeclipse上建立web Project命名为Struts2_0100_Introduction,然后配置项目的Tomcat服务器和运行环境JDK。接下来在Struts-2.3.20文件夹里apps目录下找到struts.xml文件: <struts> <constant name="struts.devMode" value="true" /> //此常量是使得当修改action name的时候,项目能够及时产生效果 <package name="default" namespace="/" extends="struts-default"> <action name="hello"> <result> /Hello.jsp </result> </action> </package> </struts> 将struts.xml文件拷到项目src目录下,接下来在项目根目录下建立编辑Hello.jsp文件,用于产生输出结果:HelloWorld。 最后就是配置项目的web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_9" 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"> <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> 这样项目就搭建好了,将项目部署到Tomcat服务器上,输入URL:http://localhost:8080/Struts2_0100_Introduction/hello.action 就得到输出结果:HelloWorld
Struts2学习笔记--HelloWorld!(2015.8.11)
最新推荐文章于 2021-02-27 07:08:55 发布