首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

struts2入门配备20110301

2012-08-25 
struts2入门配置20110301图2?新建动态Web工程对话框在“Project?Name”中键入Struts2_HelloWorld,点击“New”,

struts2入门配置20110301


图2?新建动态Web工程对话框
在“Project?Name”中键入Struts2_HelloWorld,点击“New”,出现以下对话框?


图3?新建服务器运行时对话框
选择“Apache\Apache?Tomat?v5.5”,点击“Next”,出现以下对话框?


图4新建服务器运行时对话框
点击“Finish”,关闭对话框。?


图5?Struts?2.0的lib目录
按ctr+a全选,复制,再转到Eclipse窗口,在“Project?Explorer”子窗口中选中Struts2_HelloWorld\WebContent\WEB-INF\lib,然后粘贴。经过Eclipse自动刷新“Project?Explorer”子窗口,刚才所粘贴的jar文件应该会出现在Struts2_HelloWorld\Java?Resources:?src\Libraries\Web?App?Libraries下,如图6所示:?


图6?Project?Explorer子窗口

<?xml?version="1.0"?encoding="ISO-8859-1"?>
struts2入门配备20110301<!DOCTYPE?web-app?PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN"?"http://java.sun.com/dtd/web-app_2_3.dtd">
struts2入门配备20110301<web-app>
struts2入门配备20110301????<display-name>Struts?2.0?Hello?World</display-name>
struts2入门配备20110301????<filter>
struts2入门配备20110301????????<filter-name>struts2</filter-name>????????<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
struts2入门配备20110301????</filter>
struts2入门配备20110301????<filter-mapping>
struts2入门配备20110301????????<filter-name>struts2</filter-name>
struts2入门配备20110301????????<url-pattern>/*</url-pattern>
struts2入门配备20110301????</filter-mapping>
struts2入门配备20110301????<welcome-file-list>
struts2入门配备20110301????????<welcome-file>index.html</welcome-file>
struts2入门配备20110301????</welcome-file-list>
struts2入门配备20110301</web-app>


图7?新建Other菜单
点击“Other”,出现新建对话框,如图8所示?


图8?新建对话框
点击“Next”,出现新建文件对话框,如图9所示?


图9?新建文件对话框
在“File?name”中键入sturts.xml,点击“Finish”,然后将struts.xml的内容修改为:

<!DOCTYPE?struts?PUBLIC
struts2入门配备20110301????????"-//Apache?Software?Foundation//DTD?Struts?Configuration?2.0//EN"
struts2入门配备20110301????????"http://struts.apache.org/dtds/struts-2.0.dtd">
struts2入门配备20110301<struts>
struts2入门配备20110301????<include?file="struts-default.xml"/>
struts2入门配备20110301</struts>


图10?新建Other菜单
点击“Other”,出现新建对话框,如图11所示?


图11?新建对话框
选择Web\HTML,点击“Next”出现如图12所示的对话框?


图12?新建HTML页面对话框
在“File?Name”中键入index.html,点击“Next”,出现如图13所示的对话框?


图13?模板选择对话框
点击“Finish”,将index.html的内容修改为以下内容:

<!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">
struts2入门配备20110301<html>
struts2入门配备20110301<head>
struts2入门配备20110301<meta?http-equiv="Content-Type"?content="text/html;?charset=UTF-8">
struts2入门配备20110301<title>Hello?World</title>
struts2入门配备20110301</head>
struts2入门配备20110301<body>
struts2入门配备20110301<h3>Hello?World!</h3>
struts2入门配备20110301</body>
struts2入门配备20110301</html>


图14?工程菜单
点击“Export\WAR?file”,出现如图15所示的对话框?


图15?输出对话框
选择“Web\WAR?file”,点击“Next”,出现如图16所示的对话框?


图16?输出路径对话框
输入war文件的路径(如%tomcat%\webapps\Struts2_HelloWorld.war),点击“Finish”关闭对话框。?


图17?Hello?World窗口


图18?新建菜单"
点击“New\Package”,出现如图19所示对话框


图19新建Java类包对话框
在“Name”键入tutorial,点击“Finish”关闭对话框。?


图20?新建菜单
点击“New\Class”,出现如图21所示对话框?


图21?新建Java类对话框
在“Name”中键入HelloWorld,在“Superclass”中键入com.opensymphony.xwork2.ActionSupport,点击“Finish”关闭对话框。将HelloWorld.java的内容修改为:

package?tutorial;
struts2入门配备20110301
struts2入门配备20110301import?com.opensymphony.xwork2.ActionSupport;
struts2入门配备20110301
struts2入门配备20110301struts2入门配备20110301public?class?HelloWorld?extends?ActionSupport?struts2入门配备20110301{
struts2入门配备20110301????private?String?name;
struts2入门配备20110301????
struts2入门配备20110301struts2入门配备20110301????public?String?getName()?struts2入门配备20110301{
struts2入门配备20110301????????return?name;
struts2入门配备20110301????}
struts2入门配备20110301????
struts2入门配备20110301struts2入门配备20110301????public?void?setName(String?name)?struts2入门配备20110301{
struts2入门配备20110301????????this.name?=?name;
struts2入门配备20110301????}
struts2入门配备20110301????
struts2入门配备20110301struts2入门配备20110301????public?String?execute()?struts2入门配备20110301{
struts2入门配备20110301????????name?=?"Hello,?"?+?name?+?"!";?
struts2入门配备20110301????????return?SUCCESS;
struts2入门配备20110301????}
struts2入门配备20110301}

<!DOCTYPE?struts?PUBLIC
struts2入门配备20110301????????"-//Apache?Software?Foundation//DTD?Struts?Configuration?2.0//EN"
struts2入门配备20110301????????"http://struts.apache.org/dtds/struts-2.0.dtd">
struts2入门配备20110301<struts>
struts2入门配备20110301????<include?file="struts-default.xml"/>
struts2入门配备20110301????<package?name="tutorial"?extends="struts-default">
struts2入门配备20110301????????<action?name="HelloWorld"?class="tutorial.HelloWorld">
struts2入门配备20110301????????????<result>HelloWorld.jsp</result>
struts2入门配备20110301????????</action>
struts2入门配备20110301????</package>
struts2入门配备20110301</struts>


图22?新建对话框
点击“Next”,?进入下一步,如图23所示?


图23?新建JSP对话框
在“File?name”键入SayHello.jsp,点击“Next”进入下一步,如图24所示?


color: #4b4b4b; font-size: 10.0000

热点排行