Struts2_HelloWorld_3,struts2helloworld

來源:互聯網
上載者:User

Struts2_HelloWorld_3,struts2helloworld

struts.xml的配置

 1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE struts PUBLIC 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" 4     "http://struts.apache.org/dtds/struts-2.3.dtd"> 5  6 <struts> 7     <constant name="struts.configuration.xml.reload" value="true"/> 8     <!--  9     <constant name="struts.enable.DynamicMethodInvocation" value="false" />10     <constant name="struts.devMode" value="true" />11 12     <package name="default" namespace="/" extends="struts-default">13 14         <default-action-ref name="index" />15 16         <global-results>17             <result name="error">/error.jsp</result>18         </global-results>19 20         <global-exception-mappings>21             <exception-mapping exception="java.lang.Exception" result="error"/>22         </global-exception-mappings>23 24         <action name="index">25             <result type="redirectAction">26                 <param name="actionName">HelloWorld</param>27                 <param name="namespace">/example</param>28             </result>29         </action>30     </package>31     <include file="example.xml"/>32      -->33 34     <!-- Add packages here -->35     36     <package name="default" namespace="/" extends="struts-default">37         <action name="hello">38             <result>/Hello.jsp</result>39         </action>40     </package>41     42 </struts>
View Code

namespace 為 "/",action 的 name 為 hello,訪問路徑就是:http://localhost:8080/Struts2_0100_Introduction/hello.action (.action 可以不要)

Hello.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3 <% 4 String path = request.getContextPath(); 5 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 6 %> 7 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 8 <html> 9 <head>10 <base href="<%=basePath%>" />11 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">12 <title>Hello Struts2</title>13 </head>14 <body>15 <h1>Hello Struts2</h1>16 </body>17 </html>
View Code

部署後即可訪問。 

代碼連結:http://pan.baidu.com/s/1miAy27I 提取碼:fhhk

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.