aspose file tools*
The moose likes Servlets and the fly likes sevlets and javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "sevlets and javascript" Watch "sevlets and javascript" New topic
Author

sevlets and javascript

Sid Sharama
Greenhorn

Joined: Feb 06, 2005
Posts: 11
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).]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5

<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
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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:


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
try this
out.print("<a ref=http://cgdu9:8080/servlet/CartServlet1?bookid=" +bookid1 + " target=\"main\">add to cart</a>");
Regards,
Raj.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
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).]
 
 
subject: sevlets and javascript