Solved

JSP & MySQL :make paragraph when enter into db?

Posted on 2003-11-07
14
931 Views
Last Modified: 2008-02-01
hi guys,

I have a news column for company's sports club. i need to know how to make new paragraph everytime a user press enter like what we see here. the body text is save as a BLOB field.
0
Comment
Question by:yapsing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
14 Comments
 
LVL 3

Expert Comment

by:applekanna
ID: 9706108
para1 -> If this is

para2 -> is what you are talking about

I think the \n sequence will automatically be stored in the databse itself and we need do anything specific when displaying it.

You can also parse the text if you want and then insert <p> before dispalying it ....


0
 
LVL 14

Accepted Solution

by:
kennethxu earned 50 total points
ID: 9708769
try out this jsp page and you'll have a better idea of how to handle those issues:
====================
<%!
   public static String text2html(String s, boolean preformat)
   {
       StringBuffer buf = new StringBuffer();
       for (int i=0, limit=s.length(); i<limit; i++) {
           char c = s.charAt(i);
           switch( c ) {
               case '<': buf.append( "&lt;" ); break;
               case '>': buf.append( "&gt;" ); break;
               case '&': buf.append( "&amp;" ); break;
               case '\'': buf.append( "&#39;" ); break;
               case '"': buf.append( "&quot;" ); break;
               case ' ': if(preformat && s.charAt(i+1) == ' ') buf.append( "&nbsp;" ); else buf.append( c ); break;
               case '\n': if(preformat) buf.append( "<br>" ); else buf.append( c ); break;
               default: buf.append( c );
           }
      }
      return buf.toString();
   }
%>
<% String xxx="my+String That<Contains>\"Quotes'"; %>
<% String yyy="my+String That<Contains>\"Quotes'\nand      CRLF, with a\n         long line like this aaaaaaaaa bbbbbbbbbbbb ccccccccccccc ddddddddddddddd eeeeeeeeeeeeeee ffffffffffff gggggggggggggggg hhhhhhhhhhhhhhh wwwwwwwwwwwwwwwww"; %>
<FORM NAME=abc>
<h2>Use java.net.URLEncode and javascrpt:unescape():</h2>
<INPUT TYPE="TEXT" SIZE=50 NAME="text1" VALUE=""><br>
<TEXTAREA COLS=50 ROWS=4 NAME="textarea1"></TEXTAREA><br>

<h2>Use text2html()</h2>
<INPUT TYPE="TEXT" SIZE=50 NAME="text2" VALUE="<%=text2html(xxx, false)%>"><br>
<TEXTAREA COLS=50 ROWS=4 NAME="textarea2"><%=text2html(yyy, false)%></TEXTAREA><p>

<h3>preformat=false:</h3>
<%=text2html(yyy, false)%><p>

<h3>preformat=true:</h3>
<code><%=text2html(yyy, true)%></code><br>

<h3>preformat=false in &lt;pre&gt; tag:</h3>
<pre><%=text2html(yyy, false)%></pre>
</FORM>

<script>
      abc.text1.value=unescape('<%=java.net.URLEncoder.encode(xxx).replace( '+', ' ')%>' );
      abc.textarea1.value=unescape('<%=java.net.URLEncoder.encode(yyy).replace( '+', ' ')%>' );
</script>
0
 
LVL 1

Author Comment

by:yapsing
ID: 9719330
forgive me of my slowness kennethxu, can u specifically tell me how to place the coding in the proper place?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:yapsing
ID: 9719390
An error occurred at line: -1 in the jsp file: null

Generated servlet error:
    [javac] Since fork is true, ignoring compiler setting.
    [javac] Compiling 1 source file
    [javac] Since fork is true, ignoring compiler setting.
    [javac] C:\Tomcat\work\Standalone\localhost\_\try_jsp.java:46: illegal start of expression
    [javac]    public static String text2html(String s, boolean preformat)
    [javac]    ^
    [javac] C:\Tomcat\work\Standalone\localhost\_\try_jsp.java:89: cannot resolve symbol
    [javac] symbol  : method text2html (java.lang.String,boolean)
    [javac] location: class org.apache.jsp.try_jsp
    [javac]       out.print(text2html(xxx, false));
    [javac]                 ^
    [javac] C:\Tomcat\work\Standalone\localhost\_\try_jsp.java:93: cannot resolve symbol
    [javac] symbol  : method text2html (java.lang.String,boolean)
    [javac] location: class org.apache.jsp.try_jsp
    [javac]       out.print(text2html(yyy, false));
    [javac]                 ^
    [javac] C:\Tomcat\work\Standalone\localhost\_\try_jsp.java:98: cannot resolve symbol
    [javac] symbol  : method text2html (java.lang.String,boolean)
    [javac] location: class org.apache.jsp.try_jsp
    [javac]       out.print(text2html(yyy, false));
    [javac]                 ^
    [javac] C:\Tomcat\work\Standalone\localhost\_\try_jsp.java:103: cannot resolve symbol
    [javac] symbol  : method text2html (java.lang.String,boolean)
    [javac] location: class org.apache.jsp.try_jsp
    [javac]       out.print(text2html(yyy, true));
    [javac]                 ^
    [javac] C:\Tomcat\work\Standalone\localhost\_\try_jsp.java:109: cannot resolve symbol
    [javac] symbol  : method text2html (java.lang.String,boolean)
    [javac] location: class org.apache.jsp.try_jsp
    [javac]       out.print(text2html(yyy, false));
    [javac]                 ^
    [javac] 6 errors
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9719392
did you try out the code?
this is jsp code to give you an idea of how to display new line and other special characters.

if you couldn't understand, then post whatever you have.
0
 
LVL 1

Author Comment

by:yapsing
ID: 9719420
yup gave me thw error like above
0
 
LVL 1

Author Comment

by:yapsing
ID: 9719438
ok ok, got it got it
0
 
LVL 1

Author Comment

by:yapsing
ID: 9719513
ok, my explanation is, everytime i retrieve or get a text field, the cases will check every character in the text i sent, correct?

i can replace:
this
<% String xxx="my+String That<Contains>\"Quotes'"; %>
<% String yyy="my+String That<Contains>\"Quotes'\nand      CRLF, with a\n         long line like this aaaaaaaaa bbbbbbbbbbbb ccccccccccccc ddddddddddddddd eeeeeeeeeeeeeee ffffffffffff gggggggggggggggg hhhhhhhhhhhhhhh wwwwwwwwwwwwwwwww"; %>

with this:
<% String blb = request.getParameter("strng")%>
0
 
LVL 1

Author Comment

by:yapsing
ID: 9719610
thanx anyway...
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9719719
yes, you can use it before you save to database, or after you retrieve from database right before display to html page. I would suggest later approach is better.
0
 
LVL 1

Author Comment

by:yapsing
ID: 9720202
how would the db know its a next line break when we save it?
can u explain or show me a page where i can do reference?
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9723603
db doesn't have to know what you are saving to it's clob/blob column, it will just save whatever you give to it and return the same thing when you retrieve from it.

For example, The text I'm typing here will be submitted to web server, the web server will store this text in database as is.  when it needs to be displayed, we read it from database and call the text2html method, then display it on html page.

unless you have special requirement that you must cut the string and store them in different rows.

let me know.
0
 
LVL 1

Author Comment

by:yapsing
ID: 9727616
ahh... all is clear now...

thanks
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9728373
glad that I can help :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
authenticate preemptively soap ui option 3 170
best way to search/remove a file from an EAR file 3 116
instanceof  operator in java 26 104
designing in object programming 12 105
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In order to fulfill our mission of inspiring learning in the technology community, Experts Exchange is launching a Course of the Month program. Premium and Team Account members will have access to one course per month as a part of their membership, …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question