struts2——HelloWorld

来源:互联网 发布:linux系统主要用途 编辑:程序博客网 时间:2024/06/01 14:56

1.strutx.xml的配置

<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts>    <!-- Add packages here -->    <constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default">        <action name="hello">            <result>            /jsp/Hello.jsp            </result>        </action>    </package></struts></span>

2.hello.jsp

<span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>HelloStruts2</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>    <body>    Hello Struts2 <br>  </body></html></span>
说明:

(1)struts.xml中package中的name的作用就是区别不同的包

(2)namespace是命名空间,也就是需要访问时候需要输入的地址中的一些信息,比如这个就需要输入:http://localhost:8080/项目名/hello.action

(3)<constant name="struts.devMode" value="true" />的意思就是(2)中的后面那个action可以随便写,不影响程序的运行结果

(4)<result></result>是用来返回action所对应的结果页面的。


0 0
原创粉丝点击