📜 ⬆️ ⬇️

A story about how I “fought” with xhtml + jspx + tomcat6

Good day.

In this article I would like to talk about the development of my first startup, as well as how I spent 3 hours a day because of my overconfidence lack of knowledge.

Foreword


Honestly, my hands were “scratching” for a long time to write something, and as you understand, I do not mean the useless university laboratories, but what will be useful both for IT professionals and ordinary users. And so, some time ago, we: I (the coder) and my two combat comrades (layout designer and sysadmin) decided to start working on their first startup.

Start of development


Since there was no designer, I took it upon myself to draw a template. Not to say that for me it was easy - but this is a completely different story. As a result, after reading a couple of dozen articles, having looked through the books, I coped with my task.
')
Next - layout. Our coder - a man of very strict notions about standards: if something doesn’t fit, he goes to the garbage. “Only XHTML,” he told me, and I was not against it, rather, even for, although at that time I had absolutely no idea what awaited me in the future. While there was work on the layout - I took up the core.

The first "stones"


I think it should be noted that before that I wrote under html and created template files as * .jsp, but I perfectly understood what xhtml is and how they differ. In the end, I thought: “If xhtml is more correct to create * .jspx pages” - and I did. Just at that time, the layout was ready: I ​​received an html file with resources.

I was hoping to set a high tempo from the start, so I quickly copied the markup to a jpsx file, corrected it in some places, copied resources and ran tomcat hoping to see all the beauty, but tomcat cursed me with a mistake with a glass trace that I had never seen before. I asked Google for it - "Google did not answer me, shaking my head." Although no - he certainly answered - only that did not help me. I still blindly poked, changed something, deleted it - it did not help, the “cat” stubbornly filled me with spectra. Then I gave up, no, not really, just realized that I probably should read the jspx literature after all.

As a result, I found the following errors:

1. DOCTYPE
Instead of the usual line at the beginning of the document
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Need to use a special tag.
 <jsp:output doctype-root-element="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" omit-xml-declaration="true"/> 


2. Escaped Chars
There are textarea tags on the page, inside which is the html code, and I somehow completely forgot that the < and > characters need to be converted to <and>, respectively, and of course all the others.

3. CDATA
It is used when it is necessary to select character data inside an xml document, for example, styles that are not rendered into a separate file:
 <style type=”text/css”> <![CDATA[ input {...} /*   */ ]]> </style> 


4. Markup
In some places, the single tag forgot to put / end
eg
 <img src="1.gif" width="10" height="10"> 

instead
 <img src="1.gif" width="10" height="10"/> 


5. Directives
Instead
 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 

nessesary to use
 <jsp:directive.page contentType="text/html; charset=UTF-8"/> 


All these errors broke the structure of the document, the parser could not process it and with a clear conscience threw an exception.

Having fixed all these errors, and running tomcat, I finally saw the browser (FF 3.6. *) Display the page.

However, I was glad early.

Surprise


After the last plugging, the development went livelier, we have almost reached the final stretch. For the test, I installed all the major browsers: FF, Opera, Safari, Chrome, IE. Although stop, IE of course has already been pre-installed. And by the way, he just spoiled the whole raspberry at the last moment.

For reference (lyrical digression): I have a beloved old woman xp sp3 - IE6 in it, yes I know that this is generally antiquity, but there was no such direct need to upgrade it to version 7 or 8.

I basically never use IE - only for testing cross-browser compatibility. For reasons unknown to me, when I once again decided to check how the application works in IE - I saw the message “IE cannot display the page.” I was a little surprised how he couldn’t display the “http: ⁄⁄localhost⁄” page. Jumping with tambourines - I did not achieve anything. Donkey cheerfully continued to show me the message "IE cannot display the page." Well, he is a donkey and in Africa is a donkey.

I spat on IE, especially when I received the layout - my friend swore and swore that in IE6-9 everything is displayed perfectly. And that was my mistake.

A few days passed, the development still went smoothly, without a hitch. I just wondered why IE does not work, I have direct access to the Internet, without proxies, there are no settings. I got to google - it turned out that I'm not the only one with such a problem. A couple of tips did not help, but I saw the following - "reset all settings." That's exactly what I did. And, about a miracle, this wonderful browser began to load and display pages.

I immediately decided to check it out and tried to log into my application on localhost. Having hung up a bit IE suggested I save the file. I thought it was a glitch, clicked cancel, tried to log into FF, Opera, and so on - all other browsers displayed the page. I tried again to log in via IE, and again I saw the suggestion to save the file. Saved, opened through a notebook - and saw the page layout. I asked to check out my comrades - their situation was the same.

After studying the problem, I got the following:
IE6, IE7, IE8 - offered to save the file
IE9 - normally displayed page

Suspecting something was wrong, I opened in my IE6 the layout that our layout designer sent me, html-file. IE normally displayed the page. I began to look for differences between this layout, and my own in the jspx-template, and found, at the very beginning, it was a content-type:
- my friend's content-type: text/html
- my content-type: application/xhtml+xml

“What the ...?” - I thought, but decided to try and put the content-type: text / html. In fact, it bore fruit - all browsers began to work the same way - display a blank page. Even IE. Next is the standard scheme: Firefox + Firebug, reloaded the page: the console is empty, no errors, the document structure attracted the attention: there was nothing inside, nothing was empty. I “asked” FF for the source code of the page: inside it was all the necessary document structure. I saved it and began again to look for differences from the one that was in the template on the server.

Attention attracted the following line:
 <script type="text/javascript" src="/js/jquery-1.5.1.min.js"/> 

Although in the template on the server it looked like this:
 <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script> 


And in fact, such a “transformation” was applied to all tags
And besides, with tags inside which was empty - there was the same trouble.

The decision came by itself. Wrap these tags with <! [CDATA []]>. Thus, we will force the server to give what is inside exactly in the same form without conversions, we get:

 <![CDATA[<script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>]]> 


Saved, restarted the server, tried to enter. FF displayed the page. Crossing my fingers, I launched IE. And he also displayed the page as it should look. After that, I checked in all the other major browsers - everything worked as it should.

As a conclusion


I wanted to do better, faster, not to waste time studying the bottlenecks of poorly familiar technology - in the end it turned out as always. My arrogance led to negative consequences in this situation. And it's good that mistakes were noticed during the development phase.

Source: https://habr.com/ru/post/128723/


All Articles