MyFirstStruts2

 

 

 1 package com.sdlc.action;
 2 
 3 public class HelloWorldAction {
 4 
 5     private String msg;
 6     
 7     public void setMessage(String message) {
 8         this.msg = message;
 9     }
10     
11     public String getMessage() {
12         return msg;
13     }
14 
15     public String execute()
16     {
17         this.msg="电子商务";
18         //执行该方法之后返回至名为success的视图
19         return "success";
20     }
21     
22     public static void main(String[] args) {
23         
24     }
25 
26 }
HelloWorldAction.java

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 3   <display-name>Struts2</display-name>
 4  <filter>
 5         <filter-name>struts2</filter-name>
 6         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 7     </filter>
 8 
 9     <filter-mapping>
10         <filter-name>struts2</filter-name>
11         <url-pattern>/*</url-pattern>
12     </filter-mapping>
13         <welcome-file-list>
14         <welcome-file>index.jsp</welcome-file>
15     </welcome-file-list>
16 
17 </web-app>
web.xml

 

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 4     "http://struts.apache.org/dtds/struts-2.0.dtd">
 5 
 6 <struts>
 7    <package name="sdlc" namespace="/test" extends="struts-default">
 8         <action name="helloworld" class="com.sdlc.action.HelloWorldAction" method="execute" >
 9              <result name="success">/WEB-INF/page/hello.jsp</result>
10         </action>
11     </package> 
12 </struts>
struts.xml

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10    ${message}
11 </body>
12 </html>
hello.jsp

 

 

 

   

posted @ 2013-10-16 11:40  凤凰骑士  阅读(145)  评论(0编辑  收藏  举报