struts2 学习应用(一)

基本配置:

 

 

环境:
myeclipse 版本:5.5.1
tomcat 版本:5.5
struts2 版本:struts2-core-2.0.11.1.jar
下载地址:http://struts.apache.org/
需要的包只有5个(commons-logging-1.0.4.jar;freemarker-2.3.8.jar;ognl-2.6.11.jar;struts2-core-2.0.11.1.jar;xwork-2.0.4.jar)
struts.properties 文件放在str目录下,内容:  struts.locale=zh_CN


==============================================================================================

 

 

web.xml文件格式:


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Struts Blank</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

==============================================================================================

 


在src目录下(WEB-INF--classes--struts.xml)
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="ceshi" extends="struts-default">
        <action name="ceshiAction" class="com.voole.action.DemoAction">
            <result name="success" type="redirect">/error.jsp</result>
        </action>
        <!-- Add actions here -->
    </package>
</struts>

==============================================================================================

 

  

jsp文件:

<!-- 注意后缀为action -->
  <body>
    <form action="ceshiAction.action" method="post">
    <input name="userName" value="111">
    <input name="userPass" value="222222">
    <input type="submit" value="test">
    </form>
  </body>

==============================================================================================

 

 

访问action文件:

 

import com.opensymphony.xwork2.ActionSupport;

public class DemoAction extends ActionSupport {
 
 private String userName;
 private String userPass;
 

 private String SUCCESS="success";
 

public String getUserName() {
  return userName;
 }

 public void setUserName(String userName) {
  this.userName = userName;
 }

 public void setUserPass(String userPass) {
  this.userPass = userPass;
 }

 public String getUserPass() {
  return userPass;
 }
 
 /**
  *
  */
 private static final long serialVersionUID = 1L;

 

 public String execute() throws Exception{
  System.out.println(userName);
  System.out.println(userPass);
  return SUCCESS;

 }

}

 

你可能感兴趣的:(apache,xml,Web,jsp,struts)