display Servlet response as html page in forms

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

mkushwaha
Ebase User
Posts: 29
Joined: Mon Nov 02, 2015 7:19 pm

display Servlet response as html page in forms

#1

Postby mkushwaha » Tue Jun 28, 2016 10:14 pm

I am getting a servlet response as an HTML page and I want to display as an html page. How can I make this happen ?

I tried using html component but not all element display correctly. I tried using a text component and mark as contains html and it doesn't even display the text as html. It just displays the text pasted below.

The sample servlet response is here:
http://www.heypasteit.com/clip/2RB1

Any help would be greatly appreciated :)
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Wed Jun 29, 2016 8:06 am

Assuming you want to call the servlet via a URL, the easiest ways are:
1. To embed it inside an Ebase page, use an HTML Control with an <iframe> tag
2. If it's external, just use form.callURL()
0 x

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#3

Postby dvanhussel » Wed Jun 29, 2016 11:41 am

In a project where 'no iframes' was a requirement, we have used the '<object>' HTML tag for this.

http://www.w3schools.com/tags/tag_object.asp
0 x

mkushwaha
Ebase User
Posts: 29
Joined: Mon Nov 02, 2015 7:19 pm

#4

Postby mkushwaha » Wed Jun 29, 2016 5:20 pm

Thanks Jon. I used displayUrl instead and it works for my purpose. It happens so that the html displays correctly in IE11 but doesn't render as html in chrome, it just display as text in chrome. Would you know where to look, the sample of html code is here http://www.heypasteit.com/clip/2RB1
0 x

mkushwaha
Ebase User
Posts: 29
Joined: Mon Nov 02, 2015 7:19 pm

#5

Postby mkushwaha » Wed Jun 29, 2016 10:35 pm

I dig further and found out that by manually changing the javascript inside the returned servlet response and manually pasting it into textbox and highlighting contains html renders correctly. But when I tried to automate the process using replace string. It stopped working.

Manually edited script is here
http://www.heypasteit.com/clip/2RG0


Original script
http://www.heypasteit.com/clip/2RB1

Did this to automate the process

Code: Select all

	   fields.test1.value = getResponseText&#40;input1&#41;;
	   fields.test1.value= fields.test1.value.replace&#40;'Labels = document.all&#40;"domLabels"&#41;.XMLDocument;', 'Labels = document.getElementById&#40;"domLabels"&#41;;'&#41;;
		fields.test1.value = fields.test1.value.replace&#40;'if &#40;Labels.parseError.errorCode != 0&#41;',""&#41;;
		fields.test1.value = fields.test1.value.replace&#40;"alert&#40;'Please contact your System Administrator",""&#41;;
		fields.test1.value = fields.test1.value.replace&#40;"' + Labels.parseError.reason&#41;;",""&#41;;
		fields.test1.value = fields.test1.value.replace&#40;"labelsError = true;",""&#41;;
	  fields.test1.value = fields.test1.value.replace&#40;'Label = Labels.getElementsByTagName&#40;label&#41;.item&#40;0&#41;;', 'Label = document.getElementsByTagName&#40;label&#41;.item&#40;0&#41;;'&#41;;
text field has test1 variable.

I get following error when I try to automate the process.
In javascript I would get error as "ufsmain:459 Uncaught ReferenceError: writeLabel is not defined"

In manual text entry I don't get such error. writeLabel is defined function in script tag in the html response from servlet.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#6

Postby Jon » Thu Jun 30, 2016 8:43 am

It's always going to be difficult to include a complete HTML page inside an Ebase page as part of an HTML control or as a text containing HTML (these two are really the same thing). The reason is that the Ebase page contains a structure:
<html>
<head>
JS and style sheets loaded here
</head>
<body>
controls go here
</body>
</html>

If you add an external page as part of a control, you end up with that page's <html>, <head>, <body> sections embedded inside the Ebase page's <body> tag, and this is invalid HTML. You are then relying on the tolerance of different browsers to get it working and there are no guarantees. So this approach is always flawed. It's better and more reliable to embed an external page in an <iframe> or <object> tag using an Ebase HTML control. This way you will have syntactically correct HTML and it's much easier to get it working.
0 x


Who is online

Users browsing this forum: Google [Bot] and 17 guests