Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting help..

 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just try to understand the following and pls help soon..
Suppose i m writing a letter in a textarea as follows:
<b>
Hi all,
How r u.. so so..
Pranit..
</b>
and saving the data is the database..
Next when i retrieve the data from the database and display the letter in a table column(td) the display is like this:
<b>
Hi all, How r u.. so so.. Pranit..
</b>
Now i want, how can i display the letter in the table column as i typed.. i mean just in same format..
Pranit..
 
V Srinivasan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.javaranch.com/ubb/Forum3/HTML/002075.html
see this post.
Insert "," like delimeter in yr db, while retrieving take that field and replace "," with \n (escape sequence newline char) to display as you required.
Wish you a very Happy & Prosperous New Year
V Srinivasan
[This message has been edited by V Srinivasan (edited December 31, 2001).]
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Srinivasan.. Wish u a very happy, prosperous and eventful new year.. Now coming to my point..
Where should i insert ",".. is it after each line.. can u pls show me the steps according to my post..
Pranit..
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody pls
 
Nasser Aboobaker
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pranit Saha:
<b>
Hi all,
How r u.. so so..
Pranit..
</b>

Hi Pranit,
Let us say you put a hashmark at the end of so..
then when you fetch the data from your database, run through an indexOf and look for #. locate the location replace it with +"<br>" and add the rest of the string and display.
I hope this is clear.
Nasser
<b>
Hi all,
How r u.. so so..#
Pranit..
</b>
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's clear Nasser.. but whenever someone will type in the textarea how can i get it back in that particular format.. i mean is there any way to find ezch of the line so thaqt i can place a # there.. more over how can i make HTML off in my textarea.. means if i submit any HTML code in my database.. whenever i retrieve the text it gives me the output according to the HTML code.. but i want to display the code as i typed.. like <html></html>..
Pls help..
Originally posted by Nasser Aboobaker:

Hi Pranit,
Let us say you put a hashmark at the end of so..
then when you fetch the data from your database, run through an indexOf and look for #. locate the location replace it with +"<br>" and add the rest of the string and display.
I hope this is clear.
Nasser
<b>
Hi all,
How r u.. so so..#
Pranit..
</b>
 
V Srinivasan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pranit,
Now I caught your problem, dont use textarea instead use text field for each parameter so that you can easily format while retriving. Because from textarea you will get one lengthy string, you cann't determine where you hv to place break.
Hope it is clear
Thanks and regards
V Srinivasan
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Srinivasan,
Thnaks for ur reply.. but see, as we post in javaranch.. we type in textarea rite.. and it gets stored in database.. and whenever we retrieve it we get the sam as we type.. i mean in same format.. just this i want to have.. waiting for ur reply..
Thanks in advance..
Pranit..
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai!
Try by writing small scriptlet given below at begining of ur JSP page.
<%
response.setContent("text");
%>

let me know whether it worked out or not,,

Rgds
Manohar
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manohar,
Thanks for your reply.. I tried it.. it says, method setContent(string) not found in HttpServletResponse class.. do u have any other tips..
waiting for ur reply..
Pranit..
Originally posted by Manohar Karamballi:
Hai!
Try by writing small scriptlet given below at begining of ur JSP page.
<%
response.setContent("text");
%>

let me know whether it worked out or not,,

Rgds
Manohar
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai!
Sorry! it's setContentType..
i.e response.setContentType("text");
Rgds
Manohar
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manohar,
I tried with this.. but it gives me the file download box.. whenever i try to run that .jsp..
any more tips.. pls help.. i m waiting for this solution desparately..
Pranit..
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody pls..
 
Mark Elliott
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to 'turn HTML' off as you put it then you will have to do a sting replace on the < and > characters and replace with < and > (either when you put then in the database or when you display then on on a web page again). To keep the return formating you will have to do a search and replace for all the return characters and replace then with <br> as stated previously.
New tha would happen (ignoring the spaces and ") replace < and > with "& l t ;" and "& g t;". This way the browser will not think it is looking at tags that it should hide.
[ January 15, 2002: Message edited by: Mark Elliott ]
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Thanks for your reply.. the thing is i don't have any tag problem.. the problem is, as i m typing in this textarea i get the same format back in the table column.. but in my case it doesn't happen.. all the lines come in a flow.. doesn't maintain the paragraph style as we type.. if i want to put the <br> tag after each line how can i trace the end of line.. is there any methos which gives me the end.. is it clear to u.. waiting for your reply..
Pranit..
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Pranit..
Here is some raw approcah...There might be some better solutions than tyhis that are provided by JSP itself..
Solution is
Say u got line <MARQUEE>JSP</MARQUEE> from DB to display it in some column of table.
Replace each occurance of "<" by <(Browser code for lesser than).
Something like this..
<%
out.println("<MARQUEE>jsp</MARQUEE>");
%>
Than just <MARQUEE>JSP</MARQUEE> displayed in browser instaed of
JSP moving like JSP.
Hope this helps u..
Rgds
Manohar
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While posting i found bug in javaranch site similar to one that ur facing..i.e we cannot retain '<' as it is in screen..
OK! write like this
<%
out.println("&_ltMARQUEE>Manu&_lt/MARQUEE>");
%>
remove _'s in above string to make ur code to work..
 
Mark Elliott
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason that the lines come in a flow is that you are not applying the correct html formating i.e.<br> where you get a line break. But I think that the other posts made this clear. (You will be able to see this if you do a view source on any page on this forum as your post will now have <br> in it.
To apply the right typ of line formatting write a sting replace function for your display page. I'm not going to write out all the code for one here but basically you want to for something along these lines
String formattedText(String formatMe)
{
int replaceWhere
\\ find the postion of return char

replaceWhere=formatMe.indexOf("\n");
....
some type of looping code etc to check whole string and replace at replaceWhere with <br><
....
}
You can do this before you put it in the database if you wish (this will give you one hit but alter the actuall post info) or format in the jsp/servlet at display time.
Hope that helps and I have made myself clear
[ January 16, 2002: Message edited by: Mark Elliott ]
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
thanks a lot.. i've solved my problem.. just replaced '\n' with '<br>'..
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
thanks a lot.. i've solved my problem.. just replaced '\n' with '<br>'..
really a big prob has been solved..
Thanks again..
Pranit..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic