users@glassfish.java.net

Re: URL Encoded Query String Wrong

From: <Jan.Luehe_at_Sun.COM>
Date: Fri, 01 Jun 2007 12:44:49 -0700

ITVGuy2000 wrote:

>I have a very simple JSP application that runs perfectly on Tomcat, but won’t
>run correctly on glassfish. I am guessing I have messed up some
>configuration for the web application, but I am not sure where.
>
>The JSP simply presents a form first time through, the subsequently (after
>submitted) displays the parameters to the page.
>
>When I run this application on glassfish, I get a 404-The requested resource
>() is not available. The problem seems to be that the query string is being
>incorrectly encoded.
>
>
>When I look at the address line of my browser I see:
>http://localhost:8081/JSPForm/%3fTerm%3dblah%26Definition%3dblah%250D%250A%26submit%3dProcess
>rather than:
>http://localhost:8081/JSPForm/?Term=blah&Definition=blah&submit=Process
>If I in fact type this query string by hand into the address line, my JSP
>happily displays the results blah and blah.
>
>

I'm unable to reproduce this.

I've bundled your resources into the attached WAR.
After deploying it, I can access the form and see the entered
values listed.

The only difference between Tomcat and GlassFish that I am aware of is
the default URI encoding: GlassFish uses UTF-8, whereas Tomcat uses
ISO-8859-1.

We changed the default in GlassFish to UTF-8 in an effort to fix:

https://glassfish.dev.java.net/issues/show_bug.cgi?id=2339
("i18n: deployed app doesn't launch")


Jan

>I am guessing this has to do with document/page/parameter encoding, but I am
>not sure where I have this configured wrong. I am utilizing the default
>web.xml and web-app.xml generated by NetBeans. I have tried setting the
>default character set encoding in the sun-web.xml to both ‘UTF-8’ and to
>‘ISO-8859-1’ with no effect.
>
>Am I doing something wrong, or is this a bug?
>
>ITVGuy2000
>
>---------------- index.jsp ---------------
>
><%_at_page contentType="text/html"%>
><%_at_page pageEncoding="UTF-8"%>
><%_at_page import="java.util.*"%>
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
>
><html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <title>TestJSPForm</title>
> </head>
> <body>
>
> <center>
> <h1>TestJSPForm</h1>
> Today's date is: <%= new Date() %>
> </center>
> <%
> if (request.getParameter("Term") == null &&
>request.getParameter("Definition")
> == null)
> {
> %>
> <CENTER>
> <H2>Glossary Info Form</H2>
> <FORM METHOD="GET" ACTION=”/TestJSPForm”>
> <table width="300" border="0">
> <tr>
> <td width="122">Term: </td>
> <td width="168"><input type="text" name="Term"
>size=40></td>
> </tr>
> <tr>
> <td> Definition: </td>
> <td><textarea name="Definition"
>cols="40"></textarea></td>
> </tr>
> <tr>
> <td colspan="2">&nbsp;</td>
> </tr>
> <tr>
> <td colspan="2"><div align="center">
> <input name="submit" type="submit"
>value="Process">
> </div></td>
> </tr>
> </table>
> </FORM>
> </CENTER>
> <%
> }
> else
> {
> %>
> <P align="center">
> The Glossary Entry you have provided:
> <P align="center"> <table width="482" border="0" align="center">
> <tr valign="top">
> <td width="140">Term:</td>
> <td width="332"><%= request.getParameter("Term") %></td>
> </tr>
> <tr valign="top">
> <td><P align="left">Definition: </td>
> <td><%= request.getParameter("Definition") %></td>
> </tr>
> </table>
> <% } %>
> </body>
></html>
>
>------------------- sun-web.xml ----------------------
>
><?xml version="1.0" encoding="UTF-8"?>
><!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application
>Server 9.0 Servlet 2.5//EN"
>"http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
><sun-web-app error-url="">
> <context-root>/TestJSPForm</context-root>
> <class-loader delegate="true"/>
> <jsp-config>
> <property name="classdebuginfo" value="true">
> <description>Enable debug info compilation in the generated servlet
>class</description>
> </property>
> <property name="mappedfile" value="true">
> <description>Maintain a one-to-one correspondence between static
>content and the generated servlet class' java code</description>
> </property>
> </jsp-config>
></sun-web-app>
>
>------------------- web.xml ----------------------------
>
><?xml version="1.0" encoding="UTF-8"?>
>
><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
>http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
> version="2.5">
> <session-config>
> <session-timeout>
> 30
> </session-timeout>
> </session-config>
> <welcome-file-list>
> <welcome-file>
> index.jsp
> </welcome-file>
> </welcome-file-list>
></web-app>
>
>