IDEA与Eclipse建立struts项目

一、IDEA建立struts项目

这里再构建struts项目是选择jar包出问题了,能够从新配置web

 

 

 

 

 

建立页面和action配置struts.xmlapache

启动tomcat,浏览器中运行浏览器

具体参考:tomcat

https://www.jianshu.com/p/ef5b9ed1cdb8

2 eclipse中建立

第一步:建立Web工程app

   建立一个Web工程,名为day01_struts2_demo01
第二步:导jar包
   把struts2-blank.war中的lib下全部的包导入本身建立的工程
第三步:添加配置文件
  把struts2-blank里classes目录下的struts.xml配置文件拷贝到本身建立工程的src中
  而后删除struts标签的全部内容,咱们一步步讲struts标签内容的知识
第四步:配置struts的过滤器
  在web.xml中,配置Filtereclipse

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

 配置的目的是用于拦截请求,由Struts的规则去处理请求,而不是用之前的servlet去处理
第五步:Tomcat运行Web工程
   若是tomcat运行没有报错,就表明配置成功
Struts 的Action配置讲解
目标:配置一个请求的完整流程
第一步:
   在struts中配置package和action,写以下代码
 
第二步:
  写一个HelloAction的类,须要写个sayHello方法
 
第三步:
   在WebContent中添加一个success.jsp页面
 
第四步:
  浏览器访问下面三个路径
  http://localhost:8080/day01_struts2_demo01/hello 【能正常访问】
  http://localhost:8080/day01_struts2_demo01/hello.action 【也能正常访问】
  http://localhost:8080/day01_struts2_demo01/hello.act 【不能正确访问】
   由于struts默认是处理.action的请求,或者不带action也能够,其它后缀的都不会拦截,会放行,如jsp
 

jsp

相关文章
相关标签/搜索