struts2.0----菜鸟日记三

一个简单的Struts2.0小例子

-----------First Struts2.0 Project------------ 1.建立一个web Project;

2.导入struts2.0的核心包,注意全部导入全部的lib会引起错误; commons-fileupload-1.2.1.jar commons-io-1.3.2.jar freemarker-2.3.12.jar ognl-2.6.11.jar struts2-core-2.1.2.jar xwork-2.1.1.jar

3.工程配置 3.1 struts.xml 把配置文件放在src的根目录下,在struts2.0中默认的配置文件不再是struts-default.xml,而是struts.xml 配置文件内容是:             /hello.jsp     

--其中  //代表Action的名称和实际存放位置      /hello.jsp         //表示导向页面

3.2 web.xml中必须说明filter和filter-mapping的内容      struts    org.apache.struts2.dispatcher.FilterDispatcher        struts    /*         index.jsp  

3.3 Action在Struts2.0种已经把ActionForm和Action合二为一; package com;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial") public class Hello extends ActionSupport {  private String message;

 public String getMessage() {   return message;  }

 public void setMessage(String message) {   this.message = message;  }    public String execute(){   message = message + ",Hello";   return SUCCESS;  }

}

3.4 index.jsp 起始页面

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

              My JSP 'index.jsp' starting page                          This is my first project.
         Message:           

3.5 hello.jsp 响应页面 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"     pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags" %> Insert title here   


   Back

你可能感兴趣的:(struts2.0----菜鸟日记三)