struts2 小例子(教训篇)

学了一阵子的struts2了,到了最后,想自己写个小程序,发现最简单的配置文件都 竟然能弄错,是我这几天睡眠不足么。怎么可能,爱好这门的,怎么会这样。这样真的很伤心啊。小小心灵受不了这种打击啊。。。。

教训篇吧。

1.导入jar包

2.配置web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- 过滤器的配置 -->
  <filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
   <!-- 过滤器的配置 -->
   <!-- 对应的映射文件的配置 -->
  <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
 <!-- 对应的映射文件的配置 -->
  
</web-app>

3.struts.xml(这个先放在src目录下,要是放在其他地方,需要在web.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="struts2" extends="struts-default">
    
        <action name="login" class="com.strutsStruts.LoginAction">
            <result name="success">/result.jsp</result>
        </action>
    
    </package>
    
</struts>

action文件

package com.strutsStruts;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

    @Override
    public String execute() throws Exception {

        System.out.println("ssss");
        return SUCCESS;
    }
}

看看,如此简单,就这么简单,我竟然纠结了两小时,丫的。。。。时间啊,我的时间。。。

posted on 2014-04-22 22:33  端着咖啡码农  阅读(204)  评论(0编辑  收藏  举报