jsp에서 applet을 호출하고 js에서 applet을 호출하는 방법

4869 단어
구체적인 참고 위치는 잊어버렸어요.
쓸데없는 말 작작 하고 실례를 들자.
1.download.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="java.util.*,java.sql.ResultSet"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>  </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

</head>



<body>

	       
	<br>
	<div>
<!-- 		<APPLET CODE="applet.Down.class" archive="down.jar" mayscript
			height="1" width="1"> </APPLET> -->
			
 	<applet alt="" id="my" name code="Down.class"   mayscript height="250" width="250"> </applet> 

 	<input   type="submit"   name="Submit"   value="Submit"   onClick="kc()">    
 	<script   language="javascript">      
          function   kc()   {      
             document.my.unzipFiles();      
          }    
	</script>

	</div>

	<table>
		<tr>
			<td>   </td>
			<td>  </td>
			<td>  </td>
		</tr>
</table>

</body>
</html>
		

2. 애플릿 코드
Down.java
import java.applet.Applet;
import java.awt.Color;
import java.awt.FlowLayout;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;


import javax.swing.ProgressMonitor;
import javax.swing.ProgressMonitorInputStream;


import javax.swing.*;
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import java.io.IOException;






public class Down extends Applet {
	private String filePath;
	private String fileName;
	private String url;
	private boolean bl = false;

	
	private JButton unzip;
	private String usrdirect;
	
	
	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
		System.out.println(this.filePath);
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
		System.out.println(this.fileName);
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
		System.out.println(this.url);
	}

	public void setBl() {
		this.bl = true;
		System.out.println(this.bl);
		
	}

	public void init() {
		//unzipFiles();
	}


	
	
	  public void unzipFiles()
	    {
	    	String dir ="/home/stedy/AAAPLET";
	    	usrdirect = System.getProperty("usr.home");
	    	
			JPanel loadPanel = new JPanel();
			/*JPanel loadPanel = (JPanel)this.getContentPane();*/
			loadPanel.setOpaque(false);

			loadPanel.setLayout(new FlowLayout());
			loadPanel.setBackground(Color.orange);
			
			unzip = new JButton("Unzip");
			unzip.setBackground(Color.BLUE);
			/*unzip.addActionListener(this);*/
			
			loadPanel.add(unzip);

			
			System.out.println("appletTar: init()");
	    	/*mainListener listener = new mainListener();*/
			
			/*this.setVisible(true);*/
			
			mkdir(dir);
	    }
	
	
      public   void   win()   {      
          Frame   fr   =   new   Frame("good");      
          fr.setSize(300,300);      
         fr.setVisible(true);      
        } 
	
  	public void mkdir(String mkdirName) {
		try {
			File dirFile = new File(mkdirName);
			boolean bFile = dirFile.exists();

			if (bFile == true)
				System.out.println("The folder exists.");
			else {
				System.out
						.println("The folder do not exist,now trying to create a one...");
				bFile = dirFile.mkdir();
				if (bFile == true) {

					System.out.println("mkdir OK!");
				} else {
					System.out.println("mkdir error!!");
					// infoDisplay.append("Error:mkdir.Path="+mkdirName +'
'); System.exit(1); } // infoDisplay.append("OK:mkdir.Path="+mkdirName +'
'); } } catch (Exception err) { System.err.println("ELS - Chart : Folder create anomalies"); err.printStackTrace(); } }// end of mkdir }

좋은 웹페이지 즐겨찾기