我想调用 servlet 中另一个类的方法,但出现错误...这是代码
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 中另一个类的方法,但出现错误...这是代码
最佳答案
您没有发布错误。 首先发布错误。 我认为你会因为 import 语句而收到错误。 导入 com.jnext.webapp.xxxxxx; 像这样改变代码 导入com.jnext.webapp.x;
关于java - servlet中调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32002188/