struts2的package介绍及helloworld应用


HelloWorld.java:

package blog.action;


public class HelloWorld {
    private String msg;
    
    public String getMessage() {
        return msg;
    }
    
    public String execute(){
        msg = "This is my first struts2 application!!!";
        return "success";
    }

}


HelloWorld.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>My JSP 'helloworld.jsp' starting page</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>
    ${message }
  </body>
</html>


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>
    <package name="blog" namespace="/greeting" extends="struts-default">
        <action name="helloworld" class="blog.action.HelloWorld" method="execute">
            <result name="success">/WEB-INF/page/HelloWorld.jsp</result>
        </action>
    </package>
</struts>


posted @ 2012-07-21 11:34  xzf007  阅读(321)  评论(0编辑  收藏  举报