servlet中的调用方法

时间:2015-08-14 04:16:31

标签: java

我想在servlet中调用nother类的方法但是我有错误...这是代码



package com.jnext.webapp;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.commons.codec.binary.Base64;

public class x {

	public static void jaw(String image) {
	

byte[] imageByteArray = decodeImage(image);
		
		
		FileOutputStream imageOutFile;
		try {
			imageOutFile = new FileOutputStream("D://winner.jpg");
		
		try {
			imageOutFile.write(imageByteArray);
		
		
		imageOutFile.close();
} catch (FileNotFoundException e) {
			
			e.printStackTrace();
		}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
}


public static byte[] decodeImage(String imageDataString) {	
	return Base64.decodeBase64(imageDataString.getBytes());
	
}
}

	




这是servlet



package com.jnext.webapp;

import java.io.FileOutputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jnext.webapp.xxxxxx;
import org.apache.commons.codec.binary.Base64;


public class test extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	 public test() {
        super();
        
    }
     
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	

	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		x.jaw(name);
		
		
}
}




我想在servlet中调用nother类的方法但是我有错误...这是代码

2 个答案:

答案 0 :(得分:1)

您不发布错误。 首先发布错误。 我认为你因为import语句而得到错误。 导入com.jnext.webapp.xxxxxx; 像这样改变代码 import com.jnext.webapp.x;

答案 1 :(得分:0)

您不能使用非静态方法在类中调用静态方法。 您可以在X类中将钳口功能更改为非静态功能,然后使用servlet中的对象调用钳口功能。

相关问题