Skip to main content



      Home
Home » Newcomers » Newcomers » Generic problem: Loading an Applet from inside a Servlet in Eclipse(Someone must know a solution?)
icon5.gif  Generic problem: Loading an Applet from inside a Servlet in Eclipse [message #650083] Fri, 21 January 2011 11:45 Go to next message
Eclipse UserFriend
Goodday everyone

I believe this is a generic problem, someone else must have had the same issue as the one I ran into here. I am no beginner of Eclipse, nor Java programming, however you always run into new challenges Smile

What do I want?:
I want a Servlet to produce some HTML which has an applet embedded.

What is my Problem?:
I have a Dynamic web-project, and I have made a simple Servlet in it, this works fine of course. I have also made some very simple HTML code, that basicly says Hello World and loads an applet. If I run the HTML in its own file, with the applet .class file along with, it works just fine. Also my Servlet can show the same HTML, but can not load the applet. My real problem here is that I do not know where to correctly put the .class applet file in my project workspace, so that I can refer correctly to it. Also I do not know how to refer to this path exactly.

So how do I get this to work? I works fine individually, but all tries to connect it all failed, as I could not figure out where to put the .class and then how to refer to it in the Servlet.

I hope someone understand my problem, and got a solution to this maybe obvious easy problem.

Regards
Mads Clausen

Here is the code I have used:

The Servlet:
package web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AppletServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public AppletServlet() {
super();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head>");
out.println("<title>");
out.println("Applet Test");
out.println("</title>");
out.println("</head>");
out.println("<body>");
out.println("<p>My Java Applet says:");
out.println("<APPLET CODE=\"SimpleApplet.class\" WIDTH=150 HEIGHT=25>);
out.println("</APPLET>");
out.println("</body>");
out.println("</html>");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}
}



The Applet:
import java.awt.Graphics;

public class SimpleApplet extends java.applet.Applet {
public void paint(Graphics g){
g.drawString("Hello World!", 5, 25);
}
}


The HTML in its own file:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p>My Applet Code says:</p>
<APPLET CODE="SimpleApplet.class" WIDTH=150 HEIGHT=25></APPLET>
</body>
</html>

[Updated on: Mon, 24 January 2011 10:56] by Moderator

icon7.gif  Re: Generic problem: Loading an Applet from inside a Servlet in Eclipse [message #652268 is a reply to message #650083] Thu, 03 February 2011 07:05 Go to previous message
Eclipse UserFriend
Hi,
I had the same problem days ago Smile
The problem isn't in the code, but "in the internet architecture": that is, if you want that the user-agent gets the applet, it should be gettable! But if the applet is a class of your program, how it coulds? Applet must be a different project, exported to a jar, added to the web-project as an extern resource-file and then linked by servlet in the applet tag Smile

I hope I was clear

Regards
Daniele
Previous Topic:Problem connecting to SQLSERVER
Next Topic:Send Serialized data from Applet to Servlet and Ack from Servlet
Goto Forum:
  


Current Time: Sat Nov 08 20:56:12 EST 2025

Powered by FUDForum. Page generated in 0.29572 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top