1. 程式人生 > >Structs復習 開始 第一個helloworld項目

Structs復習 開始 第一個helloworld項目

mage lte 更改 cut action mod utf fault exec

大體已經學完ssh了 感覺一起做一個項目有點難 計劃先用一下獨立的Structs 然後再把數據庫操作換成hibernate 然後在用Spring 整合 計劃用10天左右吧

但今天開始用Structs的時候 竟然發現好多東西都忘了 無從下手 所以計劃用兩天以內的時間快速復習一下Structs‘ 近兩天內寫一個基於Structs的項目 然後 根據這個項目開始後面的更改

首先搭建環境 第一個hellowold項目 由於是第二次學了 會很快 有一些講的省略的地方還希望多包含

首先 新建 web項目

然後導入jar包

技術分享圖片

web.xml配置

<?xml version="1.0" encoding="
UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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>

Struct.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.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <include file="example.xml"/> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <action name="index"> <result type="redirectAction"> <param name="actionName">HelloWorld</param> <param name="namespace">/example</param> </result> </action> </package> --> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="hello"> <result> /Hello.jsp </result> </action> </package> <!-- Add packages here --> </struts>

瀏覽器輸入:http://localhost:6666//Struts2_0100_Introduction/hello

技術分享圖片

Structs復習 開始 第一個helloworld項目