我的java历程

tomcat5.5.17+jstl1.2+servlet2.5+jsp2.1配置

tomcat5.5.17+jstl1.2+servlet2.5+jsp2.1配置

在此我使用的环境是:
tomcat5.5.17
jstl1.2
servlet2.5
jsp2.1

我以一个简单的例子hello1来说明吧,发布工程时最重要的就是目录结构了,hello1是根目录,放在tomcat中的webapps里,先看看目录结构:
hello1\index.jsp
hello1\response.jsp
hello1\WEB-INF\lib\javaee.jar
hello1\WEB-INF\lib\jsf-api.jar
hello1\WEB-INF\lib\jsf-impl.jar
hello1\WEB-INF\lib\jstl-1.2.jar
hello1\WEB-INF\web.xml

如果你按照以上目录发布工程,抛出以下异常:
(1)  java.lang.NoClassDefFoundError: javax/el/ExpressionFactory
(2)  或打开页面后显示:

HTTP Status 404 - /hello1/


type Status report

message /hello1/

description The requested resource (/hello1/) is not available.


Apache Tomcat/5.5.17


则将javaee.jar包再copy一份放在tomcat目录的common\lib下就不会了。
关于用到的javaee.jar、jsf-api.jar、jsf-impl.jar、jstl-1.2.jar这四个包可以通过myeclipse中获得,如果你安装了myeclipse5.5的话,我安装的是MyEclipse 5.5.1 GA,这四个包的所在的目录是:MyEclipse 5.5.1 GA\eclipse\plugins\com.genuitec.eclipse.j2eedt.core_5.5.1\data\libraryset\EE_5\

到此,再给出具体的文件代码吧。
(1)  hello1\index.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<html>
<head><title>Hello</title></head>
<body bgcolor="white">
<h2>Hello, my name is Duke. What's yours?</h2>
<form method="get">
<input type="text" name="username" size="25">
<p></p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>

<c:if test="${fn:length(param.username) > 0}" >
  <%@include file="response.jsp" %>
</c:if>
</body>
</html>

(2)  hello1\response.jsp

<h2><font color="black">Hello, ${param.username}!</font></h2>

(3)  hello1\WEB-INF\web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_2_5.xsd"
         version="2.5">

<jsp-config> 
 <jsp-property-group>
  <display-name>hello1</display-name>
  <url-pattern>*.jsp</url-pattern>
  <el-ignored>false</el-ignored>
  <scripting-invalid>false</scripting-invalid>
  <is-xml>false</is-xml>
  <!-- <include-prelude>/template/prelude.jspf</include-prelude> -->
  <!-- <include-coda>/template/coda.jspf</include-coda> -->
 </jsp-property-group>
</jsp-config>
</web-app>


成功之后页面显示为:

Hello, my name is Duke. What's yours?

 

Hello, afdfadsfads!

posted on 2007-07-06 13:35 landril 阅读(3774) 评论(0)  编辑  收藏 所属分类: Jsp&Servlet


只有注册用户登录后才能发表评论。


网站导航: