Applet, Application communication
Hi
Someone tell me how to do applet, application communication.
I have one standalone application, running in server and receiving connection from applets and every min. the server has to send some data back to each apllet connected.
How to do it... any sample or reffernces please..
Thanks in advance
Tomy
Can you give me example codes using RMI / Socket
thanks
Similar Messages
-
Applet/servlet communication for byte transmission
Hello all !
I wrote an applet to transfer binary file from web servlet (running under Tomcat 5.5) to a client (it's a signed applet) but I have a problem of interpretation of byte during transmission.
the code of the servlet is :
response.setContentType("application/octet-stream");
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStream(new File(
"C:\\WINDOWS\\system32\\setup.bmp"));
byte[] b = new byte[1024];
int nbRead = 1;
while (nbRead > 0) {
nbRead = fis.read(b);
System.out.println("octets lus = " + nbRead);
sos.write(b, 0, nbRead-1);
fis.close();
sos.close();et le code de l'applet qui appelle cette servlet est :
URL selicPortal = null;
try {
selicPortal = new URL(
"http://localhost:8080/AppletTest/servlet/FileManipulation");
} catch (MalformedURLException e) {
e.printStackTrace();
URLConnection selicConnection = null;
try {
selicConnection = selicPortal.openConnection();
} catch (IOException e) {
e.printStackTrace();
selicConnection.setDoInput(true);
selicConnection.setDoOutput(true);
selicConnection.setUseCaches(false);
selicConnection.setRequestProperty("Content-Type",
"application/octet-stream");
try {
InputStream in = selicConnection.getInputStream();
FileOutputStream fos = new FileOutputStream(new File(tempDir
+ "\\toto.bmp"));
byte[] b = new byte[1024];
int nbRead = in.read(b);
while (nbRead > 0) {
fos.write(b);
in.close();
fos.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}the file dowloaded is broken. it seems that bytes 01 00 or 00 01 are not correctly process.
Some ideas to help me please ?hi,
have you solved this issue.. please post me the code since i m also doing the applet/servlet communication and can use your code as reference.
how to read the content placed in the urlConnection stream in the servlet
Below is my code in applet
public void upload(byte[] imageByte)
URL uploadURL=null;
try
uploadURL=new URL("<url>");
URLConnection urlConnection=uploadURL.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-type","application/octet-stream");
urlConnection.setRequestProperty("Content-length",""+imageByte.length);
OutputStream outStream=urlConnection.getOutputStream();
outStream.write(imageByte);
outStream.close();
catch(MalformedURLException ex)
catch(IOException ex)
How can i read the byte sent on the outstream (in above code) in the servlet.
Thanks,
Mclaren -
Is there a good advanced review on applet-servlet communication
I am working on a web application and unfortunately experiencing a lot of trouble trying to use an applet as front end which interacts with a couple of servlets running on Tomcat. I need to get data from one servlet and send data to another.
There is a lot of messages posted in this and other forums about how to do this, but none of them got a response pointing to a useful advanced reference on this subject. I have reviewed some of the references given, but couldn't find a thorough detailed advanced reference on applet-servlet communication. For this I mean an exhaustive explanation of the mechanism of communication and when and when is neccesary to use each of the multiple configuration possibilities regarding content-type, message-length, request-method, connection settings, and so on.
Would anybody be so kind to show me the right direction? As I read the (literally) hundreds of messages posted on this topic, I see this info as widely useful. Most of the topic tracks ends on void or with painful no-way sentences, and maybe many people is avoiding Java technology on web application because of this problem (development delays can abort a project).This sample chapter in Java developers' guide to Servlets and Jsp focuses on Applet-Servlet communication, is a pretty good one, and is free :
http://www.javaranch.com/bunkhouse/samps/2809ch12.pdf
As to an exhaustive & complete guide that covers absolutely everything, I may be wrong but I doubt you'll find anything like that...unless there is a book somewhere dedicated to the subject. -
Applet-servlet communication, object serialization, problem
hi,
I encountered a problem with tomcat 5.5. Grazing the whole web i didn't find any solution (some guys are having the same problem but they also got no useful hint up to now). The problem is as follows:
I try to build an applet-servlet communication using serialized objects. In my test scenario i write a serialized standard java object (e.g. a String object) onto the ObjectOutputStream of the applet/test-application (it doesn't matters wheter to use the first or the latter one for test cases) and the doPost method of the servlet reads the object from the ObjectInputStream. That works fine. But if i use customized objects (which should also work fine) the same code produces an classnotfound exception. When i try to read and cast the object:
TestMessage e = (TestMessage)objin.readObject();
java.lang.ClassNotFoundException: TestMessage
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
...That seems strange to me, because if i instantiate an object of the same customized class (TestMessage) in the servlet code, the webappclassloader doesn't have any problems loading and handling the class and the code works fine!
The class is located in the web-inf/classes directory of the application. I've already tried to put the class (with and without the package structure) into the common/classes and server/classes directory, but the exception stays the same (I've also tried to build a jar and put it in the appropriate lib directories).
I've also tried to catch a Throwable object in order to get information on the cause. But i get a "null" value (the docu says, that this will may be caused by an unknown error).
I've also inspected the log files intensively. But they gave me no hint. Until now I've spend a lot of time on searching and messing around but i always get this classnotfound exception.
I hope this is the right place to post this problem and i hope that there is anyone out there who can give me some hint on solving this problem.
Kindly regards,
Danielhi, thanks for the reply,
all my classes are in the web-inf/classes of the web-app and have an appropriate package structure. thus the TestMessage class is inside a package.
i tried some names for the testclass but it didn't matter. the exception stays the same. I also tried to put the jar in the common/lib but the problem stays.
Well the problem with loaded classes: As i mentioned in the post above i can instantiate an object of TestMessage in the code without any problems (so the classloader of my webapp should know the class!!)
only when reading from the objectinputstream the classloader doesn't seem to know the class?? maybe theres a parent classloader resposible for that and doesn't know the class?
strange behaviour...
p.s. sending the same object from the servlet to the client works well
regards
daniel
Message was edited by:
theazazel -
Applet/Servlet communication - StreamCorruptedException
Hi, I'm having a problem when I try to connect to a servlet. I am using applet/servlet communication. The problem only occurs when I have lauched a crystal report via http in a new window.
After the report is launched if I try to hit my servlet I get the following error:
java.io.CorruptedStreamException: invalid stream header
Not all crystal reports I launch cause this behavior but I can see nothing in the url I use to launch the report that is out of place or different than other reports.
APPLET-SERVLET CONNECTION
try {
StringBuffer path = new StringBuffer();
path.append(ip);
path.append("servlet/DatabaseServlet?");
path.append("option=getRecords&query=").append(URLEncoder.encode(query,"UTF-8"));
URL url = new URL(path.toString());
URLConnection servletConnection = url.openConnection();
servletConnection.setUseCaches(false);
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setRequestProperty("Content-Type", "application/x-java-serialized-object");
ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
rc = (RecordCollection) inputFromServlet.readObject();
inputFromServlet.close();
} catch (Exception e) {
e.printStackTrace();
SERVLET CODE
Forwards to doPost
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("session id: " + request.getSession().getId());
this.doPost(request, response);
LAUNCHING REPORT FROM APPLET
try {
String launchURL = host + directory + report + "?promptOnRefresh=0"+ "&" +
authentication + "&" + key + "&" + startPeriods + "&" + reportYears + "&" + reportTitle + "&" endPeriods "&" + locations + "&" + reportPeriod + "&" + fiscalWeek + "&" + fiscalYear + "&" +time;
context.showDocument(new URL(launchURL), "_blank");
} catch (Exception ex) {
ex.printStackTrace();
SAMPLE URL THAT CAUSES PROBLEM
http://localhost:113/Reports/OpenToBuy_3.class?promptOnRefresh=0&user0=rpuser&password0=er34sw1&[email protected]=rpuser&[email protected]=er34sw1&user0@sub2=rpuser&[email protected]=er34sw1&promptex-key="L","L1","ALL"&promptex-start="1"&promptex-years="2004","2004"&promptex-title="Report Title"&promptex-end="1"&promptex-locs="01","03","04","05"&promptex-period="Feb 2004 [04-01]"&promptex-cw="1"&promptex-cy="2004"&promptex-time=-2-52728"
Everything works fine until I launch this report then I can no longer get data from my servlet. I thought the URL lenght for the report might be the problem but I lauch a report with a URL longer than the problem one and there I don't get the errors after. When I try to connect to the servlet the println statement in the doGet method of my servlet doesn't get printed so it's not even making it inside that method in the servlet.
Anyone have any idea what could be causing this? Anyone have any ideas what would be causing this? I'm really stumped.I've seen this problem before. Because your accessing a complete URL (ie http://<host>:<port>/xxx), you are actually creating a new session. Whenever the applet opens a connection to a servlet it is running on it's own session not the same as the JSP. This is rather obvious since the Page and Applet are separate entities.
Try sending authentication with the url. I think the syntax is:
username:password@http://localhost/xxx
However I'm not sure how well this might work for Tomcat. As for Java it may try and throw a MalformedURLException I would have to test it first - it's been a long time since I used this technique!
Wish I could be more help,
Anthony -
Problem in Applet Servlet communication in cluster
Our new production server has been configured with
clusters very recently.The application is running fine if and only if one instance
of weblogic is running.The application has two applets that communicate through a
servlet and the servlet is hosted by both the WL servers in the cluster.
Please consider the following scenario :
1. JSP#1(having embedded tag for Applet#1) is served by, say, WLInstance#1.
2. JSP#2(having embedded tag for Applet#2) is served by, say, WLInstance#2.
3. Applet#1 is loaded by BrowserInstance#1.
4. Applet#2 is loaded by BrowserInstance#2.
The way I understand applet-servlet communication is as follows :
The servlets are invoked through the url-pattern specified in web.xml - if the applet
is making use of a certain url-pattern that is mapped to servlet, then the call from
that applet will
eventually invoke a servlet on any of the two instances till a session is established,
at which point all subsequent requests from the same browser window/frame will go
to the servlet hosted on the instance where the http session was created.
(Please correct me, if I am wrong.)
So, Applet#1 will always talk to the servlet hosted by WLInstance#1 and Applet#2
will always talk to the servlet hosted by WLInstance#2.
In our case, the servlet is maintaining data structures to store all the messages
sent by diffterent instances of Applets.
The applets periodically polls the messages from those data structures.Once the messages
are polled, those are deleted from
the data structures.
As there are two different instances of the servlet, Applet#1 never gets messages
posted by Applet#2.
Is there a way to make this data structure global to both the servlet instances?
Thanks and best regards,
Subir Das
"Subir Das" <[email protected]> wrote:
>So, Applet#1 will always talk to the servlet hosted by WLInstance#1 and
>Applet#2
>will always talk to the servlet hosted by WLInstance#2.
This statement is not entirely true.
Suppose WLInstance#1 were to be brought down (for whatever reason), Applet#1 will
then talk to servlet hosted by WLInstance#2.
Server pinning could be modified by different load balancing algorithms, configurable
via containers (or hardware).
So don't count on which servlet instance your applet is going to be served by.
Instead consider to give a second look into the design of the servlet data structure
(object):
1.Read from data store, if it has been persisted.
2.If the data is client related then consider sticking the data into session, which
would then replicate to other WL instances.
3.Stateless EJB in a cluster ? Don' know much about this(yet).
My 2 cents..Good luck.
Rama
-
How to load an Applet application for 1000cards?
Hi Friends..
I want to know How to load an Applet application for 1000cards?..
Assume that, i have an Applet application that need to loaded into 1000cards..
So, how to solve this?
Do i must to load an application manually for each card?
Is there any another way?
Thanks in advance..for 1000 cards you can use a "small" printer like an evolis "dualis" or something like that
we've produced thousands of cards with this method in my company.
the pro is that you can also print the cards in the same time.
they usually have simple APIS like get_new_card_from_loader(), put_card_on_contacts(), eject_card()
you can connect any reader on the printer , the raw card contacts are available on a connector.
some printers also have contactless couplers.
but remember that deploying cards in the field is not just loading an applet.
it's also a cryptographic challenge, you need to change the card keys or anyone will be able to play with your cards, adding and removing applets as they want.
typically this is achieved by using an ultra secret mother key and whatever derivation algorithm you like using data from INIT UPDATE as diversifier. example, you can TDES cipher part of the INIT UPDATE data using the mother key as TDES key, or use something involving SHA1, using a HSM if you are serious, etc.
for your entertainment here is a high volume card personnalization machine. That's amazing.
http://www.youtube.com/watch?v=6ZBF_yKRF5w -
Asynchronous applet-servlet communication
Hi all,
I am trying to implement asynchronous applet-servlet communication and need your help. Anything would help(I tried with synchronous applet-servlet communication but doesn't solve my problem).
Thanks,http://java.sun.com/docs/books/tutorial/networking/index.html
You can open a socket connection. Bother the client and the server
can have separate threads for reading and writing and that you gives you
asynchronous communication. Later, if you think the server is generating
too many threads and not scaling, you can use features of .java.nio to
make it more scalable:
java.nio.channels -
Applet javascript communication
hi all,
I want my applet to flash the browser window, came to know that can be done
using applet javascript communication.
ne1 has ne idea how to do that.
thx in adv,
kiran???
-
Deployed DC's not appearing on the Application Communication: Configuration
whenever i deploy any WD UI DC on the portal via NWDS , i am able to successfully deploy the DC.
However i am not able to view any of my DC's on the the Application Communication: Confirguration in NWA.
i have to assign the provider systems for the DCs, so i would require the DCs to appear.
i am currently operating on CE7.2
please help in this regard.Hi Ashwin ,
While importing the service into your web dynpro you will be asked to create a new service group or use existing. If you have not selected both while importing the service the DC will not be available in the application communication as there is no service group present for that DC. So you can once again check whether a Service Group is created or not. Hope this helps.
Regards,
Rohit -
How to blink/flash applet application in task bar
How to blink/flash applet application in task bar. Is posible in java?
Message was edited by:
flalinfoNot in Java proper, since there is no platform-independent way to do it. You can use the java.awt.Window.toFront() method, but it's probably not what you were thinking.
edit:
Try http://java.sun.com/javase/6/docs/api/java/awt/TrayIcon.html#displayMessage(java.lang.String,%20java.lang.String,%20java.awt.TrayIcon.MessageType) as recently seen here -
Click a button in an applet application to call up or open another window.
Please, kindly show me how to call up or open an applet window(written in a seperate file) by clicking a button in an applet application.
Thanks
Alam Winner Ikenna
import java.awt.*;
import javax.swing.*;
/*<HTML>
<Applet code = "Qualification.class" Height = "400" width = "400"></Applet>
</HTML>*/
public class Qualification extends JApplet
JPanel p, p1, p2, p3, p4, p5, p6, p7;
JLabel heading, grad, grd, sh, uni, grs, tda, sco, toe, detrd;
JButton b;
JTextField tgrad, tgrd, tsh, tuni, tgrs, ttda, tsco, ttoe, tdetrd;
GridBagLayout gbl;
GridBagConstraints gbc;
public void init()
p = new JPanel();
p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
p4 = new JPanel();
p5 = new JPanel();
p6 = new JPanel();
p7 = new JPanel();
gbl=new GridBagLayout();
gbc=new GridBagConstraints();
p =(JPanel)getContentPane();
p.setLayout(gbl);
heading = new JLabel("QUALIFICATION DETAILS:");
grad = new JLabel("Graduation Degree Program:");
grd = new JLabel("Grade");
sh = new JLabel("School");
uni = new JLabel("University");
grs = new JLabel("Graduate Record Examination (GRE) Scores");
tda = new JLabel("Test Date:");
sco = new JLabel("Score(%)");
toe = new JLabel("TOEFL Score (If required):");
detrd = new JLabel("Details of Recent Hounors and Awards:");
tgrad = new JTextField(20);
tgrd = new JTextField(20);
tsh = new JTextField(20);
tuni = new JTextField(20);
tgrs = new JTextField(20);
ttda = new JTextField(20);
tsco = new JTextField(20);
ttoe = new JTextField(20);
tdetrd= new JTextField(20);
b = new JButton("SUMBIT");
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(heading, gbc);
p.add(heading);
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridwidth = 1;
gbc.weightx = 0;
gbl.setConstraints(grad, gbc);
p.add(grad);
gbc.gridx = 2;
gbc.gridy = 1;
gbl.setConstraints(tgrad, gbc);
p.add(tgrad);
gbc.gridx = 4;
gbc.gridy = 1;
gbl.setConstraints(grd, gbc);
p.add(grd);
gbc.gridx = 6;
gbc.gridy = 1;
gbl.setConstraints(tgrd, gbc);
p.add(tgrd);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 0;
gbc.gridy = 2;
gbl.setConstraints(sh, gbc);
p.add(sh);
gbc.gridx = 2;
gbc.gridy = 2;
gbl.setConstraints(tsh, gbc);
p.add(tsh);
gbc.gridx = 4;
gbc.gridy = 2;
gbl.setConstraints(uni, gbc);
p.add(uni);
gbc.gridx = 6;
gbc.gridy = 2;
gbl.setConstraints(tuni, gbc);
p.add(tuni);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 0;
gbc.gridy = 4;
gbl.setConstraints(grs, gbc);
p.add(grs);
gbc.gridx = 2;
gbc.gridy = 4;
gbl.setConstraints(tgrs, gbc);
p.add(tgrs);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 0;
gbc.gridy = 5;
gbl.setConstraints(tda, gbc);
p.add(tda);
gbc.gridx = 2;
gbc.gridy = 5;
gbl.setConstraints(ttda, gbc);
p.add(ttda);
gbc.gridx = 4;
gbc.gridy = 5;
gbl.setConstraints(sco, gbc);
p.add(sco);
gbc.gridx = 6;
gbc.gridy = 5;
gbl.setConstraints(tsco, gbc);
p.add(tsco);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 0;
gbc.gridy = 6;
gbl.setConstraints(toe, gbc);
p.add(toe);
gbc.gridx = 2;
gbc.gridy = 6;
gbl.setConstraints(ttoe, gbc);
p.add(ttoe);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 0;
gbc.gridy = 7;
gbl.setConstraints(detrd, gbc);
p.add(detrd );
gbc.gridx = 2;
gbc.gridy = 7;
gbl.setConstraints(tdetrd, gbc);
p.add(tdetrd);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 6;
gbc.gridy = 8;
gbl.setConstraints(b, gbc);
p.add(b);
}Edited by: [email protected] on Apr 8, 2009 1:16 PM[email protected] wrote:
Can an applet have an actionPerformed method in it and if it does, do I need to write the code in an actionPerformed method ?Sure it can. Yes if you implement from the ActionListener interface, you must override the actionPerformed method.
Secondly, The (new URL("otherApplet.html"), "_NEWWIN"); What does this stand for? It means open the html file "otherApplet.html" in a new window named NEWWIN. NEWWIN can be replaced by any name you want.
Because, the compiler complained about URL, saying that, is not a class.You need to import the URL class from java.net package. -
Please help me regarding RMI Applet Application?
Hi Friends..
Please help me describe the work-flow of RMI Applet Application..
Currently, i use Java Card 2.2.1.. In the package Java Card 2.2.1 there's an example of RMI Applet Application..
in that RMI Applet Application there are 3 Java files, namely :
1. public interface Purse extends Remote
2. public class PurseImpl extends CardRemoteObject implements Purse
3. public class PurseApplet extends Applet
There's also RMIDemo.opt file.. and in the contain of that RMIDemo.opt file, there's only PurseApplet class that would be converted to CAP file..
so, what is the use of Purse Interface and PurseImp class?.. and how to use both of them?..
Please help me regarding this..
Thanks in advance..Hi Shane, thanks for clarifying that.. :).. Ok. i'm going to learn hard..
Sorry, i've a doubt regarding this thread ..
In that thread, that's mentioned purse.jar containing :
- Purse.class
- PurseApplet.class
- PurseImpl_Stub.class
- PurseImpl.class
The only class that i'm wondering is PurseImpl_Stub.class..
Why this class required, whereas i don't found it in the RMIDemo application that shipped with JCDK 2.2.1, and JCDK 2.2.2 as well..
I've tried to create other Java Card RMI Application, but it requires the "Stub" class..
Here's the error message :
java.rmi.StubNotFoundException: com.latihan.rmi.DataMahasiswaImpl_Stub
at com.sun.javacard.ocfrmiclientimpl.JCCardObjectFactory.getRemoteObject(Unknown Source)
at com.sun.javacard.javax.smartcard.rmiclient.CardObjectFactory.getObject(Unknown Source)
at com.sun.javacard.javax.smartcard.rmiclient.JavaCardRMIConnect.getInitialReference(Unknown Source)
at testRMIClient.DataMahasiswaClient.main(DataMahasiswaClient.java:43)How to create and what's the contain of that "Stub" class?..
Can i know the source code of PurseImpl_Stub.java file?..
Thanks in advance..
Edited by: Leonardo_Carreira on Apr 13, 2010 8:27 PM -
Hello,
I've successfully created a simple client-server application that communicate through the socket,
and now converting to applet, but the following error occured on the java console
java.security.AccessControlException: access denied (java.net.SocketPermission 203.xxx.xxx.xxx:9800 connect,resolve)
that's also the web server where the applet is downloaded
when i try my computer to run the applet (changed the socket ip to 127.0.0.1 or 192.168.0.111 and run the server app) it works just fine..
but when i changed it to the public IP and put it on the webserver that's what happen..
is there any way beside change the policy?
can anyone please help?
I'm really in a big need of help
thank you..
Edited by: bigpappa on Mar 17, 2009 4:05 AM1) There will be no remote server applet. One of the clients will have to run it. Applets are always executed on the client only.
2) For applets communicating with anything else but the server they came from, they need to be signed. -
Big Problem in Applet-Servlet Communication-(Help)
I wrote an method to send serialized objects from Applet to Servlet,
the method is as following:
private ObjectInputStream postObjects (URL servlet, Serializable objs[], String sessionID) throws Exception {
ObjectInputStream in = null;
ObjectOutputStream out = null;
try{
URLConnection con = servlet.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type","application/x-java-serialized-object");
con.setAllowUserInteraction(false);
con.setRequestProperty("Cookie", sessionID);
out = new ObjectOutputStream(con.getOutputStream());
int numObjects = objs.length;
for(int x = 0; x < numObjects; x++){
out.writeObject(objs[x]);
out.flush();
out.close();
in = new ObjectInputStream(con.getInputStream());
}catch(Exception e){
e.printStackTrace(System.err);
throw e;
}finally{
return in;
when I call this method, I got the following error message in Applet console,
my platform is Salaris 5.8 + iPlanet 6.0.
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2150)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2619)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:726)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:251)
at com.shinewave.lms.core.client.ServletProxy.postObjects(ServletProxy.java:255)
at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:76)
at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
java.lang.NullPointerException
at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:77)
at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
java.lang.NullPointerException
at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:82)
at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
Please help me to solve this problem, thank you very much.Hi..
Sorry abt this. But I was hoping if u could help out on this..
I am trying to implement a applet to servlet communication...
wherin the servlet would read data from the database... and send it back to the applet which gets displayed on the applet...
But the problem is that the applet is not able to establish a connection with the servlet..
I am also using another supportive class whose object is basically passed from the servlet to the applet..
could u help me..
below is the piece of code...
APPLET:
import java.net.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class TestApplet extends JApplet implements ActionListener
JButton btnLoad;
JTextField tfEmpno, tfFname, tfLname, tfSalary;
URL url;
private String webServerStr = null;
private String hostName = "sandy";
private int port = 8085;
private String servletPath = "/jdbcTest.DBDetailsServlet";
public TestApplet()
super();
// suppress Warning Message
getRootPane().putClientProperty"defeatSystemEventQueueCheck",Boolean.TRUE);
public void actionPerformed(ActionEvent ae)
if(btnLoad.getText().equals("Load"))
if(loadData())
btnLoad.setText("Save");
else
btnLoad.setText("Load");
// saveData();
public void init()
setBackground(Color.pink);
tfEmpno = new JTextField(10);
tfFname = new JTextField(10);
tfLname = new JTextField(10);
tfSalary= new JTextField(10);
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(tfEmpno);
panel.add(tfFname);
panel.add(tfLname);
panel.add(tfSalary);
getContentPane().add(panel, BorderLayout.CENTER);
JPanel bottom = new JPanel(new FlowLayout());
btnLoad = new JButton("Load");
btnLoad.addActionListener(this);
bottom.add(btnLoad);
getContentPane().add(bottom, BorderLayout.SOUTH);
public boolean loadData()
try
System.out.println("Web Server host name: " + hostName);
webServerStr = "http://" + hostName + ":" + port + servletPath;
System.out.println("Web String full = " + webServerStr);
String servletGET = webServerStr + "?"
+ URLEncoder.encode("UserOption") + "="
+ URLEncoder.encode("AppletDisplay");
// url = new URL(getCodeBase(),"http://sandy:8080/servlet/jdbcTest.DBDetailsServlet");
System.out.println("Complete Servlet Url => " + servletGET);
url = new URL(servletGET);
URLConnection con = url.openConnection();
con.setUseCaches(false); // Turn off caching.
InputStream in = con.getInputStream();
System.out.println("\nsuccess ....... con.getInputStream() ");
ObjectInputStream ois = new ObjectInputStream(in);
System.out.println("\nsuccess ....... new ObjectInputStream(in) ");
Object object = ois.readObject();
System.out.println("\nGot the object from servlet...");
if(object != null)
System.out.println("\nObject NOT null ...");
ArrayList result = (ArrayList) object;
jdbcTest.EmployeeValue empval = (jdbcTest.EmployeeValue) result.get(0);
tfEmpno.setText(""+empval.getEmp_no());
tfFname.setText(empval.getFname());
tfLname.setText(empval.getLname());
tfSalary.setText(""+empval.getSalary());
System.out.println("\nObject processed " + result);
repaint();
return true;
catch(Exception e)
e.printStackTrace();
System.out.println("\n\n loadData()=> E X C E P T I O N : " + e + "\n");
return false;
public void saveData()
//yet to be implemented..
SERVLEt:
package jdbcTest;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DBDetailsServlet extends HttpServlet
public void doGet(HttpServletRequest req,HttpServletResponse res )throws ServletException, IOException
System.out.println("\nInside the doGet()\n");
ArrayList results = getDetails();
ObjectOutputStream oos = new ObjectOutputStream(res.getOutputStream());
oos.writeObject(results);
public void doPost(HttpServletRequest req,HttpServletResponse res )throws ServletException, IOException
System.out.println("\nInside the doPost()\n");
doGet(req,res);
public ArrayList getDetails()
try
System.out.println("\nServlet : inside GetDetails...");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:odbc:SandyDSN","","");
java.sql.Statement stmt = con.createStatement();
System.out.println("\n Statement created..");
java.sql.ResultSet rs = stmt.executeQuery("SELECT * FROM EMP WHERE EMP_NO = 222");
System.out.println("\n Query Executed...");
ArrayList results = new ArrayList();
while(rs.next())
EmployeeValue empval = new EmployeeValue();
empval.setEmp_no(rs.getLong("EMP_NO"));
empval.setFname(rs.getString("FNAME"));
empval.setLname(rs.getString("LNAME"));
empval.setSalary(rs.getLong("SALARY"));
results.add(empval);
System.out.println("\n Resultset Obtained...");
stmt.close();
con.close();
return results;
catch(Exception e)
System.out.println("Error while retreiving details....." + e);
return null;
public boolean saveDetails(EmployeeValue empval)
try
return true;
catch(Exception e)
System.out.println("Error while updating details....." + e);
return false;
The utility class EMployeeValue is as below:
package jdbcTest;
import java.io.*;
class EmployeeValue implements Serializable
private long emp_no;
private String fname;
private String lname;
private long salary;
public EmployeeValue()
super();
public EmployeeValue(long eno, String fn, String ln,long sal)
super();
setEmp_no(eno);
setFname(fn);
setLname(ln);
setSalary(sal);
public long getEmp_no()
return emp_no;
public java.lang.String getFname()
return fname;
public java.lang.String getLname()
return lname;
public long getSalary()
return salary;
public void setEmp_no(long newEmp_no)
emp_no = newEmp_no;
public void setFname(java.lang.String newFname)
fname = newFname;
public void setLname(java.lang.String newLname)
lname = newLname;
public void setSalary(long newSalary)
salary = newSalary;
Maybe you are looking for
-
Linksys E1200 Router not saving Port Forwarding changes
Hi! I am currently attempting to port forward on my Linksys E1200 Router and am not succeeding in saving my settings. I am attempting to open port 25565 though both Single Port Forwarding and Port Range Forwarding, and whenever I click the "save sett
-
I just updated from OS 10.6 to Mountain Lion. My HPC4780 wireless all-in-one will not print wirelessly, even though it indicates it is getting a wireless signal. I followd the "airport base station firmware updates" suggestions, but my computer can
-
Appletv only sees SOME tv shows
My appletv sees tv shows purchased from the itunes store, but any thing I mark as a tv show that is a video file of my own does not show up. If I change it back to movie though, it is visible. Suggestions?
-
How to quit the program in Java SE??
Hi, The program below runs perfectly fine, however once I get to the stage of quitting it doesn't work. I would like 'Press any key to continue' to appear once I have pressed q. import java.util.Scanner; public class Week7777 public static void
-
Why doesn't Bridge Recognize Canon G1X Raw Images even with ACR 6.6?
I got a new Canon G1X and upgraded my Adobe Camera Raw to version 6.6 which is supposed to recognize this camera. No matter what I do, the bridge thumbnail never appears and I cannot open the files on Photoshop. I always get an error message that th