Struts快速学习指南02(内部培训教材)-大部分素材来自于《Programming Jakarta Struts》一书

4、  配置标签库,标签库是Struts自带的一些组件库,采用JSP规范中Tag-lib的方式供大家使用,正是因为存在这么丰富的标签库,使得采用Struts的开发才显得这么方便,高效。
<web-app>

 <servlet>

  <servlet-name>controller</servlet-name>

  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

  <init-param>

   <param-name>config</param-name>

   <param-value>/WEB-INF/struts-config.xml</param-value>

  </init-param>

  <init-param>

   <param-name>host</param-name>

   <param-value>localhost</param-value>

  </init-param>

  <init-param>

   <param-name>port</param-name>

   <param-value>7001</param-value>

  </init-param>

 </servlet>

 

 <servlet-mapping>

  <servlet-name>controller</servlet-name>

  <url-pattern>*.do</url-pattern>

 </servlet-mapping>

 

 <taglib>

  <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>

  <taglib-location>/WEB-INF/struts-html.tld</taglib-location>

 </taglib>

 

 <taglib>

  <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

  <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>

 </taglib>

 

 <taglib>

  <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>

  <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>

 </taglib>

</web-app>

标签库采用<taglib>定义,<taglib>含有两个子元素,<taglib-uri><taglib-location><taglib-uri>用户定义标签库的唯一表示符,可以理解为名字,以后要在jsp页面中使用这个标签库,靠的就是它。<taglib-location>指明标签库存在的物理路径,当然,和配置文件一样,也是相对路径。

5、  设置welcome文件列表(可选步骤)

<welcome-file-list>

 <welcome-file>index.jsp</welcome-file>

</welcome-file-list>

6、  设置错误处理(可选步骤),通常的http访问异常包含404 Not Found500 Internal Error,为了提供给用户更为友好的显示,可以做如下配置:

<web-app>

 <error-page>

  <error-code>404</error-code>

  <location>/common/404.jsp</location>

 </error-page>

 

 <error-page>

  <error-code>500</error-code>

  <location>/common/500.jsp</location>

 </error-page>

</web-app>

通过如上配置,当用户访问应用中不存在的页面时,将会将用户导向到/common/404.jsp页面。同样地,当出现异常错误时,将会把/common/500.jsp显示给用户。

7、  最后,一个完整的web.xml示例如下:

<?xml version="1.0" encoding="UTF-8"?>

 

<!DOCTYPE web-app

    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app> 

 <servlet>

  <servlet-name>storefront</servlet-name>

  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

  <init-param>

   <param-name>config</param-name>

   <param-value>/WEB-INF/struts-config.xml</param-value>

  </init-param>   

  <init-param>

   <param-name>debug</param-name>

   <param-value>3</param-value>

  </init-param>

  <init-param>

   <param-name>detail</param-name>

   <param-value>3</param-value>

  </init-param>

  <load-on-startup>1</load-on-startup>

 </servlet>

 

 <servlet-mapping>

  <servlet-name>storefront</servlet-name>

  <url-pattern>/action/*</url-pattern>

 </servlet-mapping>

 

 <welcome-file-list>

  <welcome-file>index.jsp</welcome-file>  

 </welcome-file-list>

 

 <error-page>

  <error-code>404</error-code>

  <location>/common/404.jsp</location>

 </error-page>

 <error-page>

  <error-code>500</error-code>

  <location>/common/500.jsp</location>

 </error-page>

 

 <taglib>

  <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>

  <taglib-location>/WEB-INF/struts-html.tld</taglib-location>

 </taglib>

 <taglib>

  <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

  <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>

 </taglib>

 <taglib>

  <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>

  <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>

 </taglib>

</web-app>

1、  到此为止,Struts的开发环境安装算是告一段落。

Preface<br>Over the last few years, web development has turned a very important corner. Gone are the days when Java™ developers wrestled with a single JSP that contained presentation logic, database access via SQL, and navigational intelligence. Java web developers have learned from their mistakes, paid the price in debugging and maintenance time, and moved on.<br><br>The number and variety of readily available web frameworks today is immense. It's hard to point a browser at a Java technical site without finding a newly released web framework that's going to revolutionize the modern world. While some may see this as a bad thing that might divide the Java community, the truth is that the constant emergence of new frameworks is just evolution at work.<br><br>The design and construction of today's nontrivial web applications pushes developers to the limit of what's logically and physically possible. Myriad solutions are thrown at the problems these applications present. Some of the solutions stick, and as with human evolution, valuable characteristics are passed on in future generations of software. Other solutions do not—those that fail to serve the needs of users and add value usually fall by the wayside.<br><br>Through this evolutionary process, the Jakarta Struts framework (created by Craig R. McClanahan and donated to the Apache Software Foundation in 2000) has emerged as one of the best web frameworks available. This book covers Version 1.1, which contains many major enhancements over the previous Jakarta Struts release. If you are building applications, web-based or not, one of the main things you will learn from this book is that frameworks such as Struts are a great time investment.<br>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值