zoukankan      html  css  js  c++  java
  • 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;
        }
    }

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

    珍惜现在,珍惜每一分,每一秒。 从不放弃,坚持。。。。。
  • 相关阅读:
    1052. 卖个萌 (20)
    1051. 复数乘法 (15)
    1050. 螺旋矩阵(25)
    1049. 数列的片段和(20)
    1048. 数字加密(20)
    1047. 编程团体赛(20)
    1046. 划拳(15)
    怎么用js代码改变单选框的选中状态
    Dom操作--全选反选
    Scoket简介
  • 原文地址:https://www.cnblogs.com/feiguo/p/3681779.html
Copyright © 2011-2022 走看看