• Post Reply Bookmark Topic Watch Topic
  • New Topic

New line using StringBuilder class  RSS feed

 
Durga Roobini
Ranch Hand
Posts: 107
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In servlet am try parse xml,so the result data will append in StringBuilder here I have separate each sentence it come like paragragh even I use system.getproperty(line.sepator) also and "\n" also it will never change it display like paragraph how I neatly display result data in servlet
 
Syed Naved Ali
Greenhorn
Posts: 8
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Durga Roobini

It will be good if you post your code, so that it becomes easier for everyone to analyze the situation.
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you displaying the data?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are talking about displaying in the browser (please be more specific in the future), then you need to format the display using HTML just like any other page. There are many ways to get a "new line" in HTML and CSS.

What you should do is to design your HTML output first, then code the servlet to emit that.
 
Durga Roobini
Ranch Hand
Posts: 107
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I parse xml data in servlet and send to client(phonegap) even I use <br> tag also no response.first I write codings in servlet and run in web browser only for that I implement <br> tag and \n and also system.getProperty(line.separator) its not break the line in web browser also and one more all my parsed xml data append in string builder class and then only I print that data
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:What you should do is to design your HTML output first, then code the servlet to emit that.


So... what you just posted wasn't very useful. The first thing you should do is to explain to us the HTML which you need. You should be able to test that HTML yourself very simply by displaying it in a browser. Once you have that, then post it here. Along with an explanation of what you tried to do to produce that HTML.

I can also tell you that StringBuilder isn't going to be part of the problem. The problem is going to be what you are putting into the StringBuilder.
 
Durga Roobini
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I post my codings here

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
//out.println("Hai");
StringBuilder str=new StringBuilder();

response.setContentType("text/xml");
String loc=request.getParameter("loc");

try{

URL url = new URL(carrerbuilder url);
URLConnection uconn=url.openConnection();
HttpURLConnection conn=(HttpURLConnection)uconn;
conn.connect();
Object content=conn.getContent();
InputStream stream=(InputStream) content;
DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder=docBuilderFactory.newDocumentBuilder();
Document doc=docBuilder.parse(stream);
doc.getDocumentElement().normalize();
//str.append("<career>");
NodeList joblist=doc.getElementsByTagName("JobSearchResult");
for(int i=0;i<joblist.getLength();i++)
{
Node job=joblist.item(i);
if(job.getNodeType()== Node.ELEMENT_NODE){
Element firstPersonElement=(Element)job;
NodeList companytag=firstPersonElement.getElementsByTagName("Company");
Element com_name=(Element)companytag.item(0);
NodeList textComList=com_name.getChildNodes();
NodeList titletag = firstPersonElement.getElementsByTagName("JobTitle");
Element title_name = (Element) titletag.item(0);
NodeList textTitleList = title_name.getChildNodes();

NodeList didtag = firstPersonElement.getElementsByTagName("DID");
Element did_text = (Element) didtag.item(0);
NodeList textDidList = did_text.getChildNodes();


String title = ((Node) textTitleList.item(0)).getNodeValue().replaceAll("&","a");
String company = ((Node) textComList.item(0)).getNodeValue().replaceAll("&","a");
String did = ((Node) textDidList.item(0)).getNodeValue().replaceAll("&","a");
str.append(company+"<br>"); //Here all my parsed data was append in StringBuilder
//str.append(company + "\n");
}
}



}catch(Exception e){
System.out.println(e);

}

out.println(str.toString()); //Here I print my output am not using any html page I use career builder webservices here am hardcode url directly



}

}
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Durga Roobini wrote://Here I print my output am not using any html page I use career builder webservices here am hardcode url directly


If you look back in the thread you will see that two people have already asked you where you are displaying the data. If you don't answer the questions that people ask you, then you are just wasting everybody's time.
 
Durga Roobini
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already explain this one,Once Again, I want to display my output in phonegap(client)
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, you did. Although that isn't all that helpful, because PhoneGap isn't actually a client, it's a development framework. But anyway let's try the next question, which you also have been asked several times. What exactly is the output that you need to generate?
 
Durga Roobini
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK now I will leave phonegap now what I want to actually is,my url like this "http://api.carrerbuilder.com?developerkey&location=banglore" so,here I will retrieve company names from banglore in web browser,
the result is like paragraph how to separate company names line by line in my normal servlet run in web browser
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my url like this "http://api.carrerbuilder.com?developerkey&location=banglore" so,here I will retrieve company names from banglore in web browser,
the result is like paragraph


Right click on the rendered page contents in the browser and do "view source" and post the HTML content here. Do remember to wrap that content in a code block while posting it here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!