📄 showimage.java
字号:
package control;
import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.*;
import model.*;
import java.util.*;
import java.io.*;
public class ShowImage extends HttpServlet
{
public void init(ServletConfig config)throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
int imageid = Integer.parseInt((String)req.getParameter("imageid"));
CardCom com = new CardCom("jdbc:mysql://localhost/mybbs","root", "root123");
Card card = com.getCard(imageid);
String filename = card.getFileName();
FileInputStream in = new FileInputStream(filename);
int len = 10*1024*1024;
OutputStream out = res.getOutputStream();
res.reset();
res.setContentType("image/jpeg;charset=GB2312"); //本来设置为(image/jpg)显示不出来的 后来设置了成现在这样就可以了 哈哈
byte buff[] = new byte[len];
int i = 0;
while((i = in.read(buff))!=-1)
{
out.write(buff,0,i);
}
in.close();
out.flush();
out.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -