struts2 Eclipse 中集成strust2开发框架实例
下面通過建立一個(gè)小的實(shí)例具體來說明Eclipse 集成struts2,以下實(shí)例采用的為 struts2?版本為 struts2 2.2.3.1?為應(yīng)用.
1. 下載struts2的開發(fā)包
第一步: 在瀏覽器中輸入 http://apache.org
第二步:在apche的頁面項(xiàng)目中選擇struct 點(diǎn)擊連接進(jìn)入相關(guān)頁面
第三步: 點(diǎn)擊download選擇下載 struct2?,本例子中選擇 :struts2 2.2.3.1,下載完后解壓,lib中的為strut2在開發(fā)中用到的包.
?
?2. 建立WEB項(xiàng)目
第一步:打開Eclipse點(diǎn)擊[文件]->Dynamic Web Project,輸入相關(guān)信息如下圖:
??
第二步:引用java開發(fā)包tomcat包及struts2必備包.
?? (1) 應(yīng)用 tomcat服務(wù)器包文件
?? A.?右鍵Struts2->點(diǎn)擊properties?然后選擇左側(cè)的?java build path ->libraries
??? ??
?? (2) 添加jre包文件
???? ?? A.?右鍵Struts2->點(diǎn)擊properties?然后選擇左側(cè)的?java build path ->libraries
???
添加完后點(diǎn)擊ok即可.
第三步:strust2開發(fā)lib包直接拷貝到WEB-INF/lib下面即可
?
實(shí)例的建立:
1. 首先介紹實(shí)例包含的文件: struts.xml,?HelloWorldAction java類,web.xml ,HelloWorld.jsp,index.jsp
2. 內(nèi)容如下:
(1)?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" /><package name="helloworld" extends="struts-default"><action name="hello" class="com.northeasttycoon.struts2.HelloWorldAction" method="execute"><result name="success">/HelloWorld.jsp</result></action></package> </struts>?(2) web.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- northeasttycoon --> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>Struts 2</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping> </web-app>?(3) HelloWorldAction.java
/*** @author NorthEastTycoon**/ package com.northeasttycoon.struts2; public class HelloWorldAction{private String name;private String passWord;public String getPassWord() {return passWord; } public void setPassWord(String passWord) {this.passWord = passWord; } public String execute() throws Exception {return "success";}public String getName() {return name;}public void setName(String name) {this.name = name;} }?(4) HelloWorld.jsp
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Hello World</title> </head> <body>歡迎, <s:property value="name"/>登陸</br> 密碼為, <s:property value="passWord"/></br> </body> </html>?(5) 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>Hello World</title> </head> <body><h1>Hello World From Struts2</h1><form action="hello"><label for="name">Please enter your name</label><input type="text" name="name"/><br/><label for="passWord">Please enter your passWord</label><input type="text" name="passWord"/><br/><input type="submit" value="Say Hello"/></form> </body> </html>?以上為例子全部內(nèi)容經(jīng)過調(diào)試.
效果如下圖:
?
備注:
??? 作者:東北大亨
??? 博客:http://www.cnblogs.com/northeastTycoon/p/5617958.html???????????????????????????????????????????????????????????????????
版權(quán)為個(gè)人所有,歡迎大家轉(zhuǎn)載;但轉(zhuǎn)載時(shí)必須注明文章來源,且在文章開頭明顯處給明鏈接。
轉(zhuǎn)載于:https://www.cnblogs.com/northeastTycoon/p/5617958.html
總結(jié)
以上是生活随笔為你收集整理的struts2 Eclipse 中集成strust2开发框架实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。