搭建struts2框架

来源:互联网 发布:苏30mki和歼11 知乎 编辑:程序博客网 时间:2024/05/19 00:10

在eclipse中搭建struts框架

   一: 在eclipse中建一个Dynamic Web Project项目

       

   二: 需要引入的jar

       

   三:  配置web.xml文件 

         <?xml version="1.0" encoding="UTF-8"?>
         <web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com      /xml/ns/javaee"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>demo</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>   


      四:配置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="struts2" extends="struts-default">
      <action name="login_*" class="com.demo.action.DemoAction" method="{1}">
               <result name="success">/index.jsp</result>
      </action>

 </package>
</struts>

    

     五: 创建一个类(DemoAction)

     

     六:创建一个index.jsp页面

         

    

       

0 0