Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to display a frame through Servlet  RSS feed

 
Kiran H Iyer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a html as my frontpage,from there i am clicking a button,onclicking it I have to display a frame which contains some AWT componets(eg List,having some dats from the server Database).Whether I can do this with an applet instead of Frame, if possible please guide me.I will be thankful if anybody guides me in both cases> I have to do it in java and servlets only(not via JSP)
thanks to all
kiran
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never done this before- but I know that you cannot display AWT components in a JSP-unless the JSP or servlet has an applet embedded in it. here is an example of an applet embedded in a servlet-go to <href http://www.coreserlvets.com> for more examples of embedding applets within servlets.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import coreservlets.SearchSpec;
/** An applet that reads a value from a TextField,
* then uses it to build three distinct URLs with embedded
* GET data: one each for Google, Infoseek, and Lycos.
* The browser is directed to retrieve each of these
* URLs, displaying them in side-by-side frame cells.
* Note that standard HTML forms cannot automatically
* perform multiple submissions in this manner.
* <P>
* Taken from Core Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* © 2000 Marty Hall; may be freely used or adapted.
*/
public class SearchApplet extends Applet
implements ActionListener {
private TextField queryField;
private Button submitButton;
public void init() {
setFont(new Font("Serif", Font.BOLD, 18));
add(new Label("Search String:"));
queryField = new TextField(40);
queryField.addActionListener(this);
add(queryField);
submitButton = new Button("Send to Search Engines");
submitButton.addActionListener(this);
add(submitButton);
}
/** Submit data when button is pressed <B>or</B>
* user presses Return in the TextField.
*/

public void actionPerformed(ActionEvent event) {
String query = URLEncoder.encode(queryField.getText());
SearchSpec[] commonSpecs = SearchSpec.getCommonSpecs();
// Omitting HotBot (last entry), as they use JavaScript to
// pop result to top-level frame. Thus the length-1 below.
for(int i=0; i<commonSpecs.length-1; i++) {
try {
SearchSpec spec = commonSpecs[i];
// The SearchSpec class builds URLs of the
// form needed by some common search engines.
URL searchURL = new URL(spec.makeURL(query, "10"));
String frameName = "results" + i;
getAppletContext().showDocument(searchURL, frameName);
} catch(MalformedURLException mue) {}
}
}
}
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost forgot- you'll need the java plug in installed in the client's browser for them to be java enabled. Go to java.sun.com for this.
 
Kiran H Iyer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear Mr.Mathew Brown
Thanks for your reply> I like to know is it possible with Frame instead of using Applets.
thanks one more
regards
kiran
 
Manuel Palacio
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a Frame then you need to create an Applet that is only showing a Button. Then when you click it you pop up a Frame.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!