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>


转载于:https://www.cnblogs.com/xzf007/archive/2012/07/21/2873892.html

相关文章:

  • 2021-07-06
  • 2022-02-07
  • 2022-12-23
  • 2021-05-31
  • 2021-06-13
  • 2021-10-03
  • 2021-11-09
  • 2022-12-23
猜你喜欢
  • 2021-10-13
  • 2022-12-23
  • 2021-12-08
  • 2022-01-10
  • 2021-08-05
  • 2021-09-27
相关资源
相似解决方案