Problem displaying structures from MySQL database with Ajax

User 5fbed0c6cb

28-01-2010 05:25:35

I am trying to display some molecule strutures from SMILES which I retrieve from MySQL database using Ajax.


xmlhttp.responseText does return the SMILES (as I can see it from alert(xmlhttp.responseText)), but when I try to display it in Sketch using document.MSketch.setMol(xmlhttp.responseText,   

"smiles")
, it doesn't display the molecule, it doesn't give any errors either.


Attached are all the files in a rar archive. Unrar all the files to the root of marvin folder in webapps.


Environment:
java 1.6.0_18
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Apache Tomcat 6.0.20
Marvin 5.2.06

ChemAxon ebbce65bcf

29-01-2010 08:52:39

Hi staraphdar,


You have a superfluous new line character in the beginning of your check.jsp file, which is returned in the response. It is handled as if it were an empty structure, so you should remove it by the following way. The beginning of your check.jsp should look like this:


<%@ page import="java.sql.*" %><%

String q = request.getParameter("q");

...

I hope this will help.


Regards,


Roland

User 5fbed0c6cb

29-01-2010 12:50:44

Thanks roland. That worked


One question though.


Why does



<%@ page import="java.sql.*" %>
<%


String q = request.getParameter("q");



create a new line before out.print()?


Is there any official documentation from SUN that explains so?

ChemAxon ebbce65bcf

01-02-2010 08:38:02

Because there is indeed a new line character between the two JSP section.


<%@ page import="java.sql.*" %>// NEW LINE CHAR HERE
<%

I don't think it is a JSP issue, it is simply the way how Tomcat works. For example if you create a test html file which contains the code below, new line characters will still be there in the output.


 

<html>

<body>TEST</body>

</html>


Anyway, I found the following Sun documentation about JSP:


http://java.sun.com/products/jsp/syntax/2.0/syntaxref20.html


Regards,


Roland

User 5fbed0c6cb

03-02-2010 06:30:29

You are right.


Thats the way TOMCAT handles jsp.


You can also get rid of whitespaces by using


<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="java.sql.*" %>


<%

Something here

%>

Ref: http://java.sun.com/developer/technicalArticles/J2EE/jsp_21/


But regarding the HTML, I think the new line characters/whitespaces are beacuse of the default margins in the body.


You can get rid of that by using


<html>
<body style="margin:0">
TEST
</body>
</html>

ChemAxon ebbce65bcf

03-02-2010 09:43:41

This trimDirectiveWhitespaces is handy. Thanks.