strats2 (一)

 

 

1、struts2是MVC框架

 

2、struts2的开发环境搭建

 

  1》找到开发Struts2应用需要使用到的jar文件.

  2》编写Struts2的配置文件

  3》在web.xml中加入Struts2MVC框架启动配置

 

 

  1》找到开发Struts2应用需要使用到的jar文件.

 

需要下载struts2

      

      官网:
                http://struts.apache.org

      下载地址 :

            http://struts.apache.org/download.cgi#struts238  版本号:struts2.3.8

    

    

说明:

 包含:

 

 

Apps 应用

Lib 类库文件

Docs 帮助文档

Src 源代码

 

找它需要开发的jar文件  需要解压:或者找到struts-2.3.8-all\struts-2.3.8\apps下面的文件如下:

 
提供了一个空白的项目struts2-blank我们就可以在这个项目上进行开发struts2.

如果开发的过程中需要其他的jar的文件的支持 怎么办?

  需要到\struts-2.3.8-all\struts-2.3.8\lib中找相应的jar文件。

 

struts2-blank.war项目 怎么解压  --  复制到tomcat中的webapps中 启动tomcat即可

 

在apache-tomcat\bin 找到  点击启动

 

观察:

 

可以打开浏览器IE

   输入  http://localhost:8080/struts2-blank

 

 

 

找到解压后的jar文件:apache-tomcat\webapps\struts2-blank\WEB-INF\lib

 

 

支持OGNL表达式依赖的jar

 

代码生成工具,struts2用它在运行时扩展Java类

 

支持freemark 试图UI

 

java.lang包的增强

 

开发扩展的jar文件

 

文件上传

 

Struts2的核心包

 

 

Xwork所依赖的jar包

 
 

 

 

  2》编写Struts2的配置文件

 

  

对比servlet :

    新建一个登陆的项目 :

        http://localhost:8080/demo/servlet/demo.do?username=&userpass=

 

? 参数   get请求方式

 

 

  /servlet/demo.do

  

web.xml文件

   <servlet>

    <servlet-name>DemoServlet</servlet-name>

  <servlet-class>www.csdn.demo.serlvet.DemoServlet</servlet-class>

  </servlet>

 

  <servlet-mapping>

    <servlet-name>DemoServlet</servlet-name>

    <url-pattern>/servlet/demo.do</url-pattern>

</servlet-mapping>

 

过滤:过滤器

监听:监听器

 

  都需要在web.xml文件中配置

 

 

客户端 ---->web容器

                 Web.xml文件---->控制器servlet---->Model--->数据库

<----------------------------------

 

 

 

 

Struts2 独有的配置文件

       struts.xml文件

 

 存放在什么位置? 配置文件内容是什么?

 

  1、必须位于classes路径下面

开发项目的过程中我们把它放到src路径下面  编译后就会存放到classes下面

 

 

 

 

客户端 ---->web容器

                 Web.xml文件---->控制器servlet---->Model--->数据库

<----------------------------------

 

 

  3》在web.xml中加入Struts2MVC框架启动配置

web.xml文件配置  读取struts.xml文件

 

 2.1.3之前:

 org.apache.struts2.dispatcher.FilterDispatcher

 

 配置如下: 2.1.3版本后如下配置:

 

  <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>

 

 

 

注意:

   struts2读取到struts.xml的内容后,以javabean形式存放在内存中,以后struts2对用户的每次请求处理将使用内存中的数据,而不是每次都读取struts.xml文件

 

Struts1struts-config.xmlweb.xml文件中配置是一个servlet

 

 

 

 

 

 

 

 

分析第一个struts2的程序

 

   启动 :013-2-26 11:07:38com.opensymphony.xwork2.util.logging.jdk.JdkLogger info

信息: Parsing configurationfile [struts-default.xml]

2013-2-26 11:07:38com.opensymphony.xwork2.util.logging.jdk.JdkLogger info

信息: Unable to locateconfiguration files of the name struts-plugin.xml, skipping

2013-2-26 11:07:38com.opensymphony.xwork2.util.logging.jdk.JdkLogger info

信息: Parsing configurationfile [struts-plugin.xml]

2013-2-26 11:07:38com.opensymphony.xwork2.util.logging.jdk.JdkLogger info

信息: Parsing configuration file [struts.xml]

 

struts-default.xml

struts-plugin.xml

struts.xml

 

三个文件启动的过程中如果有配置相同的  那么后边的会覆盖前面的。

 

 

 

 

 

 

 

Bug记录:

 

1java.net.BindException: Address already in use:JVM_Bind

 

     分析:  你使用的tomcat被第二次或者是n次 启动    以前没有关闭 导致的一个bug

 

解决方法:

   关闭 已经启动的tomcat即可。

 

2、

      分析:找不到你请求的 url既是:servlet/demo.do

    

      解决方法:

             看你的url是否存在?  如果不存在 根据业务添加。

                               

      

3

 分析:在服务器端找不到对应的demo的action

Demo.action

 

 /csdn/demo.action

只提示 :demo没有找到

 

/csdn下面没有找到 demoaction

 

 

 

4、Bug

 

 

 

No result defined for action com.opensymphony.xwork2.ActionSupportand result success

 

 

分析:

   No result 没有结果

 

om.opensymphony.xwork2.ActionSupport  struts2所有action基类

 

 

 

 

5、java.lang.NoSuchMethodException: www.csdn.helloworld.action.DemoAction.execute()

 

Execute方法名称写的不匹配

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值