Generic problem: Loading an Applet from inside a Servlet in Eclipse [message #650083] |
Fri, 21 January 2011 11:45  |
Eclipse User |
|
|
|
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 
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.29572 seconds