Talk about the hole the applet has stepped on.

Source: Internet
Author: User

After reading my article, you will simply use the applet, and you can use the Web project to read the DLL on the user's computer or anything else you want to do. JS and directly call the applet class inside the method, and get the return value.

Don't talk about the project background. Dry up the dried goods directly.

But we still have to talk about this technology, right?

First look at how Baidu said: I am the applet

And then I used myself to put something like this in the Web, and then call the client's local DLL and read the log.

Then there is the problem. What the? You also have a website to read my local DLL. What do you think? My privacy is your random?

And then basically the browser does not support this stuff. Still have to take out my Microsoft big guy's IE ah.

Preparation: You are a javer, you will write Java programs. MyEclipse tools.

Let's start the bragging journey ~~~~~~

1. Open MyEclipse to create a new Web project (omitted here ...). Do I have to teach you how to build a project? haha haha)

2. Create a new thing called the APPLET!!!! (This should have a figure!!!!!! )

Then maybe you see this thing ~ ~ ~ generated a Java file with the following very long HTML file!!!!

2. Let's write down the contents of this Class!!!! (DIRECT copy!!!) Copy me to the following method! )

1  Public void Paint (Graphics g)  {   2      Super . Paint (g);   3      G.drawrect (0, 0, 499, 149);   4      g.DrawString ("I'm your first applet! Qaq ", 5, +); 5 }  

Actually don't want to explain what this thing means, well that doesn't explain what this means. We'll see what the effect is. (This is so willful, the guide pack!!!!! )

3. Below we make the page, let us write what can be seen on the Web page ah. The HTML file generated above is deleted directly!! I don't have to use HTML. I am the most cow, the cow, but still open the index.jsp bar.

<id= "applet"  alt= "Applet not supported in current browser"  width= "400"  height= "$"  code= "Com.jd.applet.jdapplet.class"  codebase  = "<%=basepath%>applet/"></applet>  

The above piece of code is placed in your body.

Code: is the full path of your boot file package

CODEBASE: Is your file followed by the path.

In the Webroot root folder Ah, and then put the compiled class file in, as to how to compile into Class I do not teach you, you hit me.

Let's look at the chart.

All right. Basic work completed. We're going to do something,!!!!!.

To access this page first, you will be asked to install the JRE. Of course, we have developed the general configuration is good. But it will also prompt some assorted.

Open ie!!!! first. Remember, it's ie!!!. 360 Switch to IE kernel

Then start resolving various permissions issues

Question one:

This question. We open the Control Panel-the program-java and then see:

Add an exception to your address and then we open the site and you're probably, maybe, maybe, lucky. See:

Then move your little hand, click on Run!!!!!! Just see. When when

Congratulations, your applet has been successfully run in the browser.

The following plays come!!! Run the dll!!!!!!! on the user's computer Start!!!!!!! directly

Use JNA to invoke third-party DLLs. (I am a third party!!!) Hahaha, Java call DLL a bit annoying, but not afraid, some people made us a wheel, then we use AH ah ah)

Then write a C + + DLL First:

I used the DLL written by vs2012 (followed by a slow motion of my left hand, moving up.) )

Then next the next choice [email protected]@

and then finish. In the Header Files folder, the source files folder is built with two file names. I'm calling Mymath.h and Mymath.cpp.

MYMATH.H header file write the following content

1 #pragmaOnce2   3 #ifdef math_exports4 #defineMath_api __declspec (dllexport)5 #else  6 #defineMath_api __declspec (dllimport)7 #endif  8   9 namespaceMydllTen {   One     extern "C"Math_apiintGetmax (intAintb);//function A}

Mymath.cpp header file write the following content

1#include"stdafx.h"  2#include"mymath.h"  3   4 namespaceMydll5 {  6     intGetmax (intAintb//function7     {  8         returna > B?a:b; 9     }  Ten      One}

Then build, and then go to the directory of this project to find the debug directory to find your dll!

So our DLL is ready. Copy to the location you want. I'll put it in the C-packing catalogue here.

The following start test JNA (Have to spit groove, online full Nima copy identical, not so you hit me!!!!!!! I'm going to write a dll!!!!!! that's not the system itself. Don't blow it. Let's start. )

Bring the JNA package into your project first. Then copy the code!! Haha, put the following code into your applet that class!!!

1   Public Interface extends Library {  2     Mydll Instance = (Mydll) native.loadlibrary ("C:\\mydll.dll", Mydll.  Class);   3     int getmax (int A,int//4   

Then write a Main method test test!!! See if we can get the results.

1  Public Static void Main (string[] args) {2     int a = Mydll.Instance.getMax (2,50); 3     System.out.println (a); 4 }

I wrote this method is relatively large, the output of 50.

So I call this DLL and use the method is completely oj8k.

OK, let's start with a jar package. Make our way into a jar bag.

Http://www.cnblogs.com/kxdblog/p/4383438.html

Directly with the MyEclipse to hit the jar package refer to the above address, do not want to type again.

Then the preparation is done.

Then this DLL is placed in the customer that, we want to access the Web, through the applet is not impossible, but it needs a permission Ah!!!! No, you are an applet, you can do it, then my computer 200G small movies are not all you stole.

Then we need to sign the jar package we just finished.

Http://www.cnblogs.com/tqsummer/archive/2011/01/19/1939013.html

This address is perfectly signed,!!!!!!!!!!. You continue to follow the operation.

After we signed the file, we got it. It's going to be a hey.

Look at the project structure.

Delete the structure of the resume from the beginning and copy the files directly to the applet.

Then change the contents of the index.jsp.

 1  <  applet  id  = "applet"   Alt  = "The current browser does not support applets"   = ""  height  = "  code  = "Com.jd.applet.jdapplet.class"   codebase  = "<%=basepath%>applet/"   archive  = "Applet_fat.jar"  ></ applet  >  

Let's add a property: Archive write your packaged jar name and oj8k it.

We visit the next item again to see the report does not error!!!!!.

Change the tip?? No problem, accept and run. Yes, it's still our little cutie.

Here is the time to show the technology, applets and JS direct communication.!!!!!! On the code!!! Add a button first.

1 <  type= "button"  onclick= "Test ()"> I want to interact with DLL!!! </ Button >

Then it's JS.

1  <script type= "Text/javascript" >2       function  Test () {3         var applet = document.getElementById ("applet"); 4         var a=Applet.getmax ();//This is the method we wrote in Java.  5        alert (a);//Popup result 6      }7   </script >

We revisit the next item.

Successfully interacts with the DLL and gets the results. At this point, congratulations on your completion.

Talk about the hole the applet has stepped on.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.