重温JSP之一

1、一个WEB应用程序的所必须的目录结构为:WEB-INF/lib,WEB-INF/classes, 以及一个部署文件:web.xml。

2、写得任何一个Servlet或JSP页面,要想让它们直接运行,须在部署文件web.xml配置好,Servlet的配置标记为:<servlet/>和<servlet-map/>,而JSP文件的配置标记为:<jsp-config/>下面的子元素<jsp-property-group/>。我这里写的是最基本的,详细配置需参考web.xml文件对应的DTD文件。

3、今天用MYECLIPSE3.2+TOMCAT5.5写了测试页面,居然发现自己现在对JSP语法很是陌生,看来书还是得常看,有事没事就应该去翻翻。我的写JSP页面如下:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="test.Person" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <%out.println(basePath); %>
   
    <title>My JSP 'MyJsp.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

  </head>
 
  <body>
    <%
     ArrayList list = new ArrayList(6);
    Person p = new Person("xionghuayun","Male",23);
    list.add(p);
    request.setAttribute( "test", list );
     %>
     <display:table name="test" />
  </body>
</html>

对应的web.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <jsp-config>
  <taglib>
   <taglib-uri>http://displaytag.sourceforge.net/</taglib-uri>
   <taglib-location>/WEB-INF/displaytag-11.tld</taglib-location>
  </taglib>
  <jsp-property-group>
   <url-pattern>/TestDisplayTag.jsp</url-pattern>
   <url-pattern>/MyJsp.jsp</url-pattern>
  </jsp-property-group>
 </jsp-config>
 <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

</web-app>

4、好啦,今天就写到这里,每天坚持,一天一点。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值