struts2学习笔记1

HelloWorld实例(快速上手)

struts2.1.8

新建一个web项目,
按照目录结构 添加struts.xml&所用到的jar
struts2学习笔记1_第1张图片

struts2学习笔记1_第2张图片

struts.xml(配置各请求要执行的action)
默认执行execute方法。使用method=””指定执行的方法 

 

 

 

<?xml version="1.0" encoding="GBK" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
 "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2_HelloWorld_001" extends="struts-default">
<action name="HelloWorld" class="com.suning.demo.HelloWorld">
<result name="success">/Hello.jsp</result>
</action>
</package>
</struts>

 

 

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html">
</head>

<body>
<s:property value="message"/>
</body>
</html>

 

package com.suning.demo;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {
	private String message;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String execute() {
		this.message = "Hello World yangying";
		return SUCCESS;
	}
}

  

 

URL:http://localhost:8080/struts2_001_HelloWorld/HelloWorld                                       (HelloWorld在Struts.xml中指定action name) 

 

代码没有贴出来,放到 :https://struts2-001.googlecode.com/svn/trunk/

是鄙人第一篇博文,请大家多多谅解。

 

你可能感兴趣的:(apache,html,xml,struts,SVN)