• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sevlets and javascript

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

my servlet response should generate a html page having
<a href=someotherservlet>clickhere</a> as part of response.
when that href is clicked 'someotherservlet' is called.so far it is fine.
now i want this 'someotherservlet'to display the result/response not in the current frame but another frame, say
frame2.
how do i do it ?
ii) while generating the response in servlet as a html page can i have some script embedded in out.prinln(" ")statements of the servlet.
thank you,
sri

[This message has been edited by bmw (edited September 01, 2000).]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<a href="someotherservlet" target="NotherFrame" >clickhere</a>
>> while generating the response in servlet as a html page can i have some script embedded in
out.prinln(" ")statements of the servlet.
Sure, why not? You will have to be careful of escaping quotes
correctly, but there is nothing magic about script statements.
Bill
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:

<a href="someotherservlet" target="NotherFrame" >clickhere</a>
>> while generating the response in servlet as a html page can i have some script embedded in
out.prinln(" ")statements of the servlet.
Sure, why not? You will have to be careful of escaping quotes
correctly, but there is nothing magic about script statements.
Bill


hi,
this is servlet response:
out.print("<a href=http://cgdu9:8080/servlet/CartServlet1?bookid=" +bookid1 + " >add tocart<a>");
bookid1 is a parameter in urlrewriting.servlet is doing fine.but i want its reult in the 'rightframe'
i tried TARGET in form ,href tags.the most i am getting is a new window.
other frame title is -'rightframe'
now,please rewrite that statement so it would work.
thank you
sri
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depending on the browser, you actually need to be careful with quotes on the name supplied to target. I know that Netscape gets confused. Try the target frame name both with and without quotes:
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this
out.print("<a ref=http://cgdu9:8080/servlet/CartServlet1?bookid=" +bookid1 + " target=\"main\">add to cart</a>");
Regards,
Raj.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sri,
I cut and paste a part of code from one of my application. This works with both Netscape and IE.
The vars nextHref (String) and page no (int), qStirngBuffer (StringBuffer) are properly defined in the servlet.

The only difference this code and others code is a missing " "(double quotes) for the href = "....." part.
SAMPLE CODE
-----------
StringBuffer formBodyBuffer=new StringBuffer();
formBodyBuffer.append( "<a href =\"/accnt/servlet/AMSServlet?");
formBodyBuffer.append("destination=");
formBodyBuffer.append(nextHref);
formBodyBuffer.append("&pageNo=");
formBodyBuffer.append((pageNo+1));
formBodyBuffer.append(qStringBuffer.toString());
formBodyBuffer.append( "\" TARGET=\"body\"> Next Page </a>");

out.print(formBodyBuffer.toString());

So yours could be,
------------------
StringBuffer formBodyBuffer=new StringBuffer();
formBodyBuffer.append( "<a href =\"http://cgdu9:8080/servlet/CartServlet1?");
formBodyBuffer.append("bookid=");
formBodyBuffer.append(bookid1);
formBodyBuffer.append( "\" TARGET=\"ANOTHER_FRAME_NAME\"> Add to Cart </a>");
out.print(formBodyBuffer.toString());

[ For better PERFORMANCE
Since servlets are loaded into memory and stay in memory and serves the requests, It is always good idea to use StringBuffers instead of Strings. Whenever we use "first string" + "SecondString" 2 new String Objects are created. But when we use Stringbuffer only 1 StringBuffer object is created in memory and how many appends we make , the new appends are not creating any NEW String objects , instead , they are appended to the old StringBuffer objects. In this way we reduce the no. of new objects created in memory and the servlets can stay in memory for a longer period without any "Out of memory problem" . This is the reason of the StringBuffer in the sample code Oc course , we have to use StringBuffer.toString() when we need the String format of the contents in the StringBuffer Object.
]
2. For writing out javascripts, we can just out.print("...."); like any other output. As bill said we have to take care of any special chars which the browser can interpret as different. For this you just write a sample code in a paper and write BOTH System.out.println("...") as well as out.println("...") and in the console window whether they are sent correctly.
regds
maha anna

[This message has been edited by maha anna (edited September 11, 2000).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic