创建action
class="java" name="code">package com.demo.action; public class HelloWorld { private String mess = "我的第一个应用"; public String execute(){ return "success"; } public String getMess() { return mess; } public void setMess(String mess) { this.mess = mess; } }
?
配置struts.xml
<!-- name 为其他包继承用 namespace 为访问--> <package name="usermanager" extends="struts-default" namespace="/usermanager"> <action name="top" class="com.demo.action.HelloWorld" method="execute" > <result name="success">/WEB-INF/page/mess.jsp</result> </action> </package>
?
创建视图
<%@ 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></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> ${mess } <br> </body> </html>
?
?
浏览器访问路径:http://127.0.0.1:8080/struts2/usermanager/top
?
?
OK。