cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aamir Majeed <aamirmajee...@yahoo.com>
Subject [HELP]Exception during processing of servletgenerator
Date Fri, 04 Apr 2003 06:11:35 GMT
 
Hi,

I am using ServletGenerator and I continuously find java.io.UTFDataFormatException: Invalid
byte 2 of 2-byte UTF-8 sequence

Below is my Servlet code 

 

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.PrintWriter;

import java.io.IOException;

import com.mysql.jdbc.Driver;

import java.sql.Connection;

import java.sql.Statement;

import java.sql.ResultSet;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.io.File;

import java.io.FileOutputStream;

 

public class MyServlet extends HttpServlet 

{

  //private static final String CONTENT_TYPE = "text/xml; charset=windows-1252";

  private static final String CONTENT_TYPE = "text/xml;charset=iso-8859-1";

  private static final String DOC_TYPE;

  private Connection conn=null;

  Statement smt=null;

  private String dburl="jdbc:mysql:///test2";

  public void init(ServletConfig config) throws ServletException

  {

    super.init(config);

    System.out.println("In the init of my servlet");

    try {

    Class.forName("com.mysql.jdbc.Driver").newInstance();

    conn=DriverManager.getConnection(dburl);

    smt=conn.createStatement();

    }

    catch(ClassNotFoundException ex)

    {

      ex.printStackTrace();

    }

    catch(SQLException ex)

    {

      ex.printStackTrace();

    }

    catch(Exception ex)

    {

      ex.printStackTrace();

    }

  }

 

  /**

   * Process the HTTP doGet request.

   */

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException

  {

    //File file=new File("file.txt");

    //FileOutputStream output=new FileOutputStream(file);

    StringBuffer strbuff=new StringBuffer();

    /*  if (DOC_TYPE != null)

    {

      //strbuff.append(DOC_TYPE);

    } */

    /*

    try {

    ResultSet rs=smt.executeQuery("SELECT * FROM school;");

    

    strbuff.append("<schools>");

    while (rs.next()) {

      strbuff.append("<school");

      strbuff.append("name=\"");

      strbuff.append(rs.getString("NAME"));

      strbuff.append("\"  class=\"");

      strbuff.append(rs.getString("CLASSES"));

      strbuff.append("\"");

      strbuff.append("/>");

    }

    }

    catch (Exception ex) 

    {

      ex.printStackTrace();

    }

    

    strbuff.append("</schools>");

    */

    response.setContentType(CONTENT_TYPE);

    

    PrintWriter out = response.getWriter();

    

    //output.write(strbuff.toString().getBytes());

    //output.flush();

    //output.close();

    System.out.println(strbuff.toString());

    out.println("<schools><school name=\"My School\" class=\"My Class\"/></schools>");

    out.close();

  }

}

and following is my xslt code

 

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

       <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">

<html>

<head>

<title>Servlet Response Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

</head>

<body>

<table width="75%" border="1" cellpadding="2" cellspacing="2" bordercolor="#000000">

  <tr bgcolor="#999999"> 

    <td><font color="#FFFFFF">School name</font></td>

    <td><font color="#FFFFFF">class name</font></td>

  </tr>

  <xsl:for-each select="school">

  <tr> 

    <td><xsl:value-of select="@name"/></td>

    <td><xsl:value-of select="@class"/></td>

  </tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

 

plz fix this 

Regards

 



---------------------------------
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
Mime
View raw message