Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTML Tags Display in Servlet Java File

 
John G Wright
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sending the request from the client (browser) to the server. In Servlet.java file, I am trying to embed html tags in .java files in println,
ie
System.out.println("<a href="login.html">Login</a><br>")

The above println statment is getting displayed as a string in Mozilla(ver 17.1) whereas I am getting a proper hyperlink in IE( ver 6 ).

What needs to be done to get the same in Mozilla ?

Thanks
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you sure it is "System.out.println"?
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that all your servlet is outputting, or is it also outputting appropriate <html>, <head> and <body> elements?

Is the content type of the servlet output text/html?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64694
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out will not send the string to the response.
 
John G Wright
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all for the support. My clarifications are as follows :

System.out will not send the string to the response.

are you sure it is "System.out.println"?


It is out.println where out is the object to PrintWriter

Is the content type of the servlet output text/html?


I am getting the values from the input type 'text' from html page and updating in the database. The program has got no errors and can update the rows in the db table. The program works correctly in IE and not in Mozilla where out.println("<a href="login.html">Login</a><br>") printing as a string in the html page instead of giving me the hyperlink. The same not happening in IE where I am getting the proper hyperlink.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64694
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did not answer the question.
 
John G Wright
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to understand the question clearly.

Let me keep it very simple.

out.println("<a href="login.html">Login</a><br>") is displayed as

<a href="login.html">Login</a><br> in Mozilla 17.1

whereas I open the same html page with IE 6, I am getting the proper hyperlink of Login which when I click going to login.html page.

Whats the correct way of embedding html tags in .java file ? Am I doing it right ?r Do I need to be browser specific in embedding html tags ?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64694
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to find out what the content type of the request is. Before knowing that, any other speculation is useless.

Open the debugger in the browser (Chrome's is really good) and look at the network activity. Find the response's content type.

If you are going to be working on the web, these are essential tools you need to know how to use.
 
John G Wright
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please excuse me for lack of knowledge as I am a beginner and for a very very late reply. Thanks for the introduction to Dev Tools in the Chrome Browser.

I figured out the error and it is so simple. By default, Eclipse's internal browser content type set to text/html. So if I try to embed the HTML tags , I am getting the proper HTML output.

But in case of Chrome, the default set content type is plain/text and so if I am not mentioning text/html explicitly as set content type and trying to embed HTML tags say for example out.println("hr") [out being object to printwriter] it is printing as a string instead of HTML page. So if I want to open the link in chrome, I need to set to text/html if I embed HTML tags in servlets.


Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic