歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Eclipse helios 配置Struts2圖解

Eclipse helios 配置Struts2圖解

日期:2017/3/1 10:37:47   编辑:Linux編程
  1. <?xml version="1.0" encoding="GBK" ?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">
  5. <struts>
  6. </struts>

本文章環境:

1. Eclipse for JavaEE developer Helios

2.Struts 2.3.1.1

3. tomcat 7.0.6

配置前提:配置好tomcat,本文省略配置tomcat步驟

1、創建一個Dynamic Web Project

2.點擊next

3.看到output folder為build\classes,和傳統的WEB-INF\classes有所差別;

4.

配置web.xml在WEB-INF中;

配置struts.xml在src中;

將struts核心類庫導入WEB-INF\lib中;

5.編寫web.xml

[html]
  1. <?xml version="1.0" encoding="GBK"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  3. <filter>
  4. <filter-name>struts2</filter-name>
  5. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  6. </filter>
  7. <filter-mapping>
  8. <filter-name>struts2</filter-name>
  9. <url-pattern>/*</url-pattern>
  10. </filter-mapping>
  11. </web-app>


6.編寫struts.xml

[html]
  1. <?xml version="1.0" encoding="GBK" ?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">
  5. <struts>
  6. </struts>

編寫Hello world

1.創建一個Hello.jsp 並且內容為Hello struts2!!!

2.配置struts.xml

[html]
  1. <struts>
  2. <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
  3. <package name="HelloPackage" namespace="/" extends="struts-default">
  4. <action name="Hello">
  5. <result>/Hello.jsp</result>
  6. </action>
  7. </package>
  8. </struts>

3.部署並在浏覽器中填寫 http://localhost:8888/StrutsDemo01/Hello

Copyright © Linux教程網 All Rights Reserved