struts2_20140720

      有这样的感觉:前面学的东西弄会了,过了一段时间又感觉陌生了,还要重新开始。这次想个好办法,把写的程序用博客记录下来,把自己的学历历程用博客的形式呈现出来,一来可以方便复习,而来可以以后开发程序可以快速上手,而且代码有快速参考价值。

     struts 2第一节:

     第一步:新建web project,默认index.jsp.

     第二步:在src目录下,新建(或者从struts包中拷贝)struts.xml文件。导入类库。struts.xml代码:

                   

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
  
  <package name="myPackage" extends="struts-default">
      <action name="first">
         <result>
             /first.jsp
         </result>
      </action>
  </package>
  
</struts>    

  第三步:web.xml文件更改:

  

<?xml version="1.0" encoding="UTF-8"?>
<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" version="3.0">
  <display-name>struts2_20140720</display-name>
  <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>

    第二步和第三步在myeclipse中可以自动完成。选定工程名称-->右键--->myeclipse--->project-facets--->install apache struts 2

     第三步:index.jsp中添加链接标签

    

<a href="first.action">struts.2</a>

第四步:新建first.jsp

部署,ok!

 

     

posted @ 2014-07-20 22:03  CSER_think more  阅读(123)  评论(0编辑  收藏  举报