The encoding declaration is required in the text declaration

Discuss exceptions related to Java and how these exceptions can be resolved.

Moderator: umajava

The encoding declaration is required in the text declaration

Postby umajava » Thu Dec 20, 2007 11:34 am

Problem
org.apache.jasper.JasperException: The encoding declaration is required in the text declaration

Probable solution / reason
I noticed this problem while creating an XHTML-MP file. and I had

Code: Select all
<?xml version="1.0" charset="UTF-8" ?>


as my first line, this problem was rectified when I moved some JSP scriptlet code to the beginning

e.g.

Initially the code was

Code: Select all
<?xml version="1.0" charset="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<%@ page import="java.sql.*,java.util.*" %>
<jsp:useBean id="DBCon" class="dbcon.DBConnection" scope="session"></jsp:useBean>


Then the code was changed to

Code: Select all
<%@ page import="java.sql.*,java.util.*" %>
<jsp:useBean id="DBCon" class="dbcon.DBConnection" scope="session"></jsp:useBean>

<?xml version="1.0" charset="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>



I am not sure why this should cause a problem but the exception is raised because your XML or XHTML file do not have

Code: Select all
<?xml version="1.0" charset="UTF-8" ?>


The above line of code. Add this line of code and this should solve the problem.

If there are any other solutions to this problem, please post them.
User avatar
umajava
Site Admin
 
Posts: 117
Joined: Thu May 26, 2005 4:59 am

Return to Exception Handling

Who is online

Users browsing this forum: No registered users and 1 guest

cron