tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eleonor...@gmx.net
Subject Re: servlet works, jsp not, why? (Tomcat 5.0)
Date Thu, 14 Aug 2008 17:56:32 GMT
> I'm going to guess the servlet spec version in your web.xml isn't up to 
> a level that supported the JSTL expression language.  What's your 
> web.xml look like?

web.xml looks:
------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!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>
   <display-name>Eine Web - Applikation</display-name>

   <!-- Definition eines symbolischen Servlet-Namens -->
   <servlet>
      <servlet-name>HelloWorldServlet</servlet-name>
      <servlet-class>
         de.akdabas.jli.j2ee.servlets.HelloWorld
      </servlet-class>
   </servlet>

   <!-- Beispiel-Konfiguration des Datenbank-Servlets -->
   <servlet>
      <servlet-name>DatabaseServlet</servlet-name>
      <servlet-class>
         de.akdabas.jli.j2ee.servlets.DatenbankServlet
      </servlet-class>
      <init-param>
         <param-name>jdbcClass</param-name>
         <param-value>com.mysql.jdbc.Driver</param-value>
      </init-param>
      <init-param>
         <param-name>dbURL</param-name>
         <param-value>jdbc:mysql://localhost:3306/javatest</param-value>
      </init-param>
      <init-param>
         <param-name>username</param-name>
         <param-value>javauser</param-value>
      </init-param>
      <init-param>
         <param-name>password</param-name>
         <param-value>javadude</param-value>
      </init-param>
   </servlet>

   <!-- Konfiguration des ImageServlets -->
   <servlet>
      <servlet-name>ImageServlet</servlet-name>
      <servlet-class>
         de.akdabas.jli.j2ee.servlets.ImageServlet
      </servlet-class>
   </servlet>

   <!-- Binden des symbolischen Namens an eine URL -->
   <servlet-mapping>
      <servlet-name>HelloWorldServlet</servlet-name>
      <url-pattern>/servlets/HelloWorld</url-pattern>
   </servlet-mapping>

   <!-- Binden des Datenbank-Servlets an eine URL -->
   <servlet-mapping>
      <servlet-name>DatabaseServlet</servlet-name>
      <url-pattern>/servlets/DatenbankServlet</url-pattern>
   </servlet-mapping>

   <!-- Binden des Image-Servlets an eine URL -->
   <servlet-mapping>
      <servlet-name>ImageServlet</servlet-name>
      <url-pattern>/servlets/DynamicImage</url-pattern>
   </servlet-mapping>

</web-app>
------------------------------

> 
> --David
> 
> ge wrote:
> > Hi,
> >
> > Servlet works, jsp not. Why?
> >
> > Result of servlet:
> > --------------------
> > Datensätze
> > jdbc:mysql://localhost:3306/javatest	com.mysql.jdbc.Driver
> > javauser	javadude
> > Name	Vorname
> > 1 	hello
> > 2 	hellox
> >
> > Result of jsp:
> > -----------------
> > Results
> > ${row.foo} 	${row.bar}
> >
> > Servlet source code:
> > ---------------------
> > package de.akdabas.jli.j2ee.servlets;
> >
> > import java.io.PrintWriter;
> > import java.io.IOException;
> > import java.sql.Statement;
> > import java.sql.ResultSet;
> > import java.sql.Connection;
> > import java.sql.DriverManager;
> > import java.sql.SQLException;
> >
> > import javax.servlet.http.HttpServlet;
> > import javax.servlet.http.HttpServletRequest;
> > import javax.servlet.http.HttpServletResponse;
> > import javax.servlet.ServletException;
> >
> > /** Erzeugte dynamischen Inhalt aus Datenbank-Daten */
> > public class DatenbankServlet extends HttpServlet {
> >
> >    /** Globale Variable: Die geöffnete Datenbank-Verbindung */
> >    private Connection connection;
> >    private String driver;
> >    private String dbURL;
> >    private String dbUser; 
> >    private String dbPass; 
> >    /** Initialisieren der Datenbank-Verbindung */
> >    public void init(javax.servlet.ServletConfig config)
> >       throws ServletException {
> >
> >       // Init der Superklasse aufrufen !
> >       super.init(config);
> >
> >       // Parameter aus web.xml auslesen
> >  //     String
> >       driver = config.getInitParameter("jdbcClass");
> >       dbURL =  config.getInitParameter("dbURL");
> >       dbUser = config.getInitParameter("username");
> >       dbPass = config.getInitParameter("password");
> >
> >       // Aufbau der Datenbank-Verbindung
> >       try {
> >          Class.forName(driver);
> >          connection =
> >             DriverManager.getConnection(dbURL, dbUser, dbPass);
> >       } catch(Exception exc) {
> >          throw new ServletException("SQL-Exception in init()", exc);
> >       }
> >
> >    }
> >
> >
> >    /** Bearbeiten von POST-Requests analog zu GET */
> >    public void doPost(HttpServletRequest request,
> >                       HttpServletResponse response)
> >                       throws IOException, ServletException {
> >
> >       // Weiterleiten des Request an die Methode doGet()
> >       doGet(request, response);
> >    }
> >
> >    /** Service-Methode zur Verarbeitung von GET-Requests */
> >    public void doGet(HttpServletRequest request,
> >                      HttpServletResponse response)
> >                      throws IOException, ServletException {
> >
> >       // Binden der (in JSPs vordefinierten) Variable out
> >       PrintWriter out = response.getWriter();
> >
> >       // Erzeugen von HTML-Code ...
> >       out.println("<html><body><center>Datensätze</center>");
> >      
> out.println("<table><tr><td>"+dbURL+"</td><td>"+driver+"</td></tr>");
> >      
> out.println("<table><tr><td>"+dbUser+"</td><td>"+dbPass+"</td></tr>");
> >       out.println("<table><tr><td>Name</td><td>Vorname</td></tr>");
> >       // Aufbau der Datenbank-Verbindung
> >
> >       try {
> >          Class.forName(driver);
> >          connection =
> >             DriverManager.getConnection(dbURL, dbUser, dbPass);
> >       } catch(Exception exc) {
> >          out.println("<center>Datensätze2</center>");
> >          throw new ServletException("SQL-Exception in init()", exc);
> >       }
> >
> >       // ... und Einbinden von dynamischem Inhalt
> >       try {
> >          ResultSet rs = null;
> >          try {
> >             Statement stmt = connection.createStatement();
> >             rs = stmt.executeQuery
> >                     ("Select * from testdata");
> >
> >             while(rs.next() == true) {
> >                out.println("<tr><td>" + rs.getString(1) + "</td>");
> >                out.println("<td>" + rs.getString(2) + "</td></tr>");
> >             }
> >
> >          } finally {
> >             rs.close();
> >          }
> >
> >       } catch(SQLException exc) {
> >          out.println("<html><body><center>Datensätze3</center>");
> >          throw new ServletException("SQL-Exception", exc);
> >       }
> >
> >       out.println("</table></body></html>");
> >    }
> >
> >    /** Wird verwendet um belegte Ressourcen freizugeben */
> >    public void destroy() {
> >       try {
> >          // Freigeben von Datenbank-Ressourcen
> >          connection.close();
> >       } catch(SQLException exc) {
> >          log("SQL-Exception in destroy()", exc);
> >       }
> >    }
> > }
> > ----------------
> >
> > jsp code:
> > ---------
> > <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
> > <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
> >
> > <sql:query var="rs"
> dataSource="jdbc:mysql://localhost:3306/javatest?user=javauser&password=javadude">
> > select id, foo, bar from testdata
> > </sql:query>
> >
> > <html>
> >   <head>
> >     <title>DB Test</title>
> >   </head>
> >   <body>
> >
> >   <h2>Results</h2>
> >   
> >
> > <table>
> > <c:forEach var="row" items="${rs.rows}">
> > <tr>
> >    <td> <c:out value="${row.foo}"/></td>
> >    <td> <c:out value="${row.bar}"/></td>
> > </tr>
> > </c:forEach>
> > </table>
> >   </body>
> > </html>
> > ---------------------------
> > jsp's servlet code:
> > -------------------
> > package org.apache.jsp.jsp;
> >
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > import javax.servlet.jsp.*;
> >
> > public final class test_jsp extends
> org.apache.jasper.runtime.HttpJspBase
> >     implements org.apache.jasper.runtime.JspSourceDependent {
> >
> >   private static java.util.Vector _jspx_dependants;
> >
> >   private org.apache.jasper.runtime.TagHandlerPool
> _jspx_tagPool_sql_query_var_dataSource;
> >   private org.apache.jasper.runtime.TagHandlerPool
> _jspx_tagPool_c_forEach_var_items;
> >   private org.apache.jasper.runtime.TagHandlerPool
> _jspx_tagPool_c_out_value_nobody;
> >
> >   public java.util.List getDependants() {
> >     return _jspx_dependants;
> >   }
> >
> >   public void _jspInit() {
> >     _jspx_tagPool_sql_query_var_dataSource =
> org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
> >     _jspx_tagPool_c_forEach_var_items =
> org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
> >     _jspx_tagPool_c_out_value_nobody =
> org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
> >   }
> >
> >   public void _jspDestroy() {
> >     _jspx_tagPool_sql_query_var_dataSource.release();
> >     _jspx_tagPool_c_forEach_var_items.release();
> >     _jspx_tagPool_c_out_value_nobody.release();
> >   }
> >
> >   public void _jspService(HttpServletRequest request,
> HttpServletResponse response)
> >         throws java.io.IOException, ServletException {
> >
> >     JspFactory _jspxFactory = null;
> >     PageContext pageContext = null;
> >     HttpSession session = null;
> >     ServletContext application = null;
> >     ServletConfig config = null;
> >     JspWriter out = null;
> >     Object page = this;
> >     JspWriter _jspx_out = null;
> >     PageContext _jspx_page_context = null;
> >
> >
> >     try {
> >       _jspxFactory = JspFactory.getDefaultFactory();
> >       response.setContentType("text/html");
> >       pageContext = _jspxFactory.getPageContext(this, request, response,
> >       			null, true, 8192, true);
> >       _jspx_page_context = pageContext;
> >       application = pageContext.getServletContext();
> >       config = pageContext.getServletConfig();
> >       session = pageContext.getSession();
> >       out = pageContext.getOut();
> >       _jspx_out = out;
> >
> >       out.write('\n');
> >       out.write('\n');
> >       out.write('\n');
> >       if (_jspx_meth_sql_query_0(_jspx_page_context))
> >         return;
> >       out.write("\n");
> >       out.write("\n");
> >       out.write("<html>\n");
> >       out.write("  <head>\n");
> >       out.write("    <title>DB Test</title>\n");
> >       out.write("  </head>\n");
> >       out.write("  <body>\n");
> >       out.write("\n");
> >       out.write("  <h2>Results</h2>\n");
> >       out.write("  \n");
> >       out.write("\n");
> >       out.write("<table>\n");
> >       if (_jspx_meth_c_forEach_0(_jspx_page_context))
> >         return;
> >       out.write("\n");
> >       out.write("</table>\n");
> >       out.write("  </body>\n");
> >       out.write("</html>");
> >     } catch (Throwable t) {
> >       if (!(t instanceof SkipPageException)){
> >         out = _jspx_out;
> >         if (out != null && out.getBufferSize() != 0)
> >           out.clearBuffer();
> >         if (_jspx_page_context != null)
> _jspx_page_context.handlePageException(t);
> >       }
> >     } finally {
> >       if (_jspxFactory != null)
> _jspxFactory.releasePageContext(_jspx_page_context);
> >     }
> >   }
> >
> >   private boolean _jspx_meth_sql_query_0(PageContext _jspx_page_context)
> >           throws Throwable {
> >     PageContext pageContext = _jspx_page_context;
> >     JspWriter out = _jspx_page_context.getOut();
> >     //  sql:query
> >     org.apache.taglibs.standard.tag.rt.sql.QueryTag _jspx_th_sql_query_0
> = (org.apache.taglibs.standard.tag.rt.sql.QueryTag)
> _jspx_tagPool_sql_query_var_dataSource.get(org.apache.taglibs.standard.tag.rt.sql.QueryTag.class);
> >     _jspx_th_sql_query_0.setPageContext(_jspx_page_context);
> >     _jspx_th_sql_query_0.setParent(null);
> >     _jspx_th_sql_query_0.setVar("rs");
> >     _jspx_th_sql_query_0.setDataSource(new
> String("jdbc:mysql://localhost:3306/javatest?user=javauser&password=javadude"));
> >     int[] _jspx_push_body_count_sql_query_0 = new int[] { 0 };
> >     try {
> >       int _jspx_eval_sql_query_0 = _jspx_th_sql_query_0.doStartTag();
> >       if (_jspx_eval_sql_query_0 !=
> javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
> >         if (_jspx_eval_sql_query_0 !=
> javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE) {
> >           out = _jspx_page_context.pushBody();
> >           _jspx_push_body_count_sql_query_0[0]++;
> >          
> _jspx_th_sql_query_0.setBodyContent((javax.servlet.jsp.tagext.BodyContent) out);
> >           _jspx_th_sql_query_0.doInitBody();
> >         }
> >         do {
> >           out.write("\n");
> >           out.write("select id, foo, bar from testdata\n");
> >           int evalDoAfterBody = _jspx_th_sql_query_0.doAfterBody();
> >           if (evalDoAfterBody !=
> javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
> >             break;
> >         } while (true);
> >         if (_jspx_eval_sql_query_0 !=
> javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE)
> >           out = _jspx_page_context.popBody();
> >           _jspx_push_body_count_sql_query_0[0]--;
> >       }
> >       if (_jspx_th_sql_query_0.doEndTag() ==
> javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
> >         return true;
> >     } catch (Throwable _jspx_exception) {
> >       while (_jspx_push_body_count_sql_query_0[0]-- > 0)
> >         out = _jspx_page_context.popBody();
> >       _jspx_th_sql_query_0.doCatch(_jspx_exception);
> >     } finally {
> >       _jspx_th_sql_query_0.doFinally();
> >      
> _jspx_tagPool_sql_query_var_dataSource.reuse(_jspx_th_sql_query_0);
> >     }
> >     return false;
> >   }
> >
> >   private boolean _jspx_meth_c_forEach_0(PageContext _jspx_page_context)
> >           throws Throwable {
> >     PageContext pageContext = _jspx_page_context;
> >     JspWriter out = _jspx_page_context.getOut();
> >     //  c:forEach
> >     org.apache.taglibs.standard.tag.rt.core.ForEachTag
> _jspx_th_c_forEach_0 = (org.apache.taglibs.standard.tag.rt.core.ForEachTag)
> _jspx_tagPool_c_forEach_var_items.get(org.apache.taglibs.standard.tag.rt.core.ForEachTag.class);
> >     _jspx_th_c_forEach_0.setPageContext(_jspx_page_context);
> >     _jspx_th_c_forEach_0.setParent(null);
> >     _jspx_th_c_forEach_0.setVar("row");
> >     _jspx_th_c_forEach_0.setItems(new String("${rs.rows}"));
> >     int[] _jspx_push_body_count_c_forEach_0 = new int[] { 0 };
> >     try {
> >       int _jspx_eval_c_forEach_0 = _jspx_th_c_forEach_0.doStartTag();
> >       if (_jspx_eval_c_forEach_0 !=
> javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
> >         do {
> >           out.write("\n");
> >           out.write("<tr>\n");
> >           out.write("   <td> ");
> >           if (_jspx_meth_c_out_0(_jspx_th_c_forEach_0,
> _jspx_page_context, _jspx_push_body_count_c_forEach_0))
> >             return true;
> >           out.write("</td>\n");
> >           out.write("   <td> ");
> >           if (_jspx_meth_c_out_1(_jspx_th_c_forEach_0,
> _jspx_page_context, _jspx_push_body_count_c_forEach_0))
> >             return true;
> >           out.write("</td>\n");
> >           out.write("</tr>\n");
> >           int evalDoAfterBody = _jspx_th_c_forEach_0.doAfterBody();
> >           if (evalDoAfterBody !=
> javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
> >             break;
> >         } while (true);
> >       }
> >       if (_jspx_th_c_forEach_0.doEndTag() ==
> javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
> >         return true;
> >     } catch (Throwable _jspx_exception) {
> >       while (_jspx_push_body_count_c_forEach_0[0]-- > 0)
> >         out = _jspx_page_context.popBody();
> >       _jspx_th_c_forEach_0.doCatch(_jspx_exception);
> >     } finally {
> >       _jspx_th_c_forEach_0.doFinally();
> >       _jspx_tagPool_c_forEach_var_items.reuse(_jspx_th_c_forEach_0);
> >     }
> >     return false;
> >   }
> >
> >   private boolean _jspx_meth_c_out_0(javax.servlet.jsp.tagext.JspTag
> _jspx_th_c_forEach_0, PageContext _jspx_page_context, int[]
> _jspx_push_body_count_c_forEach_0)
> >           throws Throwable {
> >     PageContext pageContext = _jspx_page_context;
> >     JspWriter out = _jspx_page_context.getOut();
> >     //  c:out
> >     org.apache.taglibs.standard.tag.rt.core.OutTag _jspx_th_c_out_0 =
> (org.apache.taglibs.standard.tag.rt.core.OutTag)
> _jspx_tagPool_c_out_value_nobody.get(org.apache.taglibs.standard.tag.rt.core.OutTag.class);
> >     _jspx_th_c_out_0.setPageContext(_jspx_page_context);
> >     _jspx_th_c_out_0.setParent((javax.servlet.jsp.tagext.Tag)
> _jspx_th_c_forEach_0);
> >     _jspx_th_c_out_0.setValue(new String("${row.foo}"));
> >     int _jspx_eval_c_out_0 = _jspx_th_c_out_0.doStartTag();
> >     if (_jspx_th_c_out_0.doEndTag() ==
> javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
> >       return true;
> >     _jspx_tagPool_c_out_value_nobody.reuse(_jspx_th_c_out_0);
> >     return false;
> >   }
> >
> >   private boolean _jspx_meth_c_out_1(javax.servlet.jsp.tagext.JspTag
> _jspx_th_c_forEach_0, PageContext _jspx_page_context, int[]
> _jspx_push_body_count_c_forEach_0)
> >           throws Throwable {
> >     PageContext pageContext = _jspx_page_context;
> >     JspWriter out = _jspx_page_context.getOut();
> >     //  c:out
> >     org.apache.taglibs.standard.tag.rt.core.OutTag _jspx_th_c_out_1 =
> (org.apache.taglibs.standard.tag.rt.core.OutTag)
> _jspx_tagPool_c_out_value_nobody.get(org.apache.taglibs.standard.tag.rt.core.OutTag.class);
> >     _jspx_th_c_out_1.setPageContext(_jspx_page_context);
> >     _jspx_th_c_out_1.setParent((javax.servlet.jsp.tagext.Tag)
> _jspx_th_c_forEach_0);
> >     _jspx_th_c_out_1.setValue(new String("${row.bar}"));
> >     int _jspx_eval_c_out_1 = _jspx_th_c_out_1.doStartTag();
> >     if (_jspx_th_c_out_1.doEndTag() ==
> javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
> >       return true;
> >     _jspx_tagPool_c_out_value_nobody.reuse(_jspx_th_c_out_1);
> >     return false;
> >   }
> > }
> > --------------------------------------
> >
> >
> > Thanks in advance for any help: Eleonora

-- 
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message