package com.system.servlets;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Redirect
*/
@WebServlet("/Redirect")
public class Redirect extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
System.out.println("servlet is intialized");
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("image/jpeg");
ServletOutputStream out;
out = response.getOutputStream();
FileInputStream fin = new FileInputStream("/home/mpatil/Desktop/Ram/downloads/gmail image.jpg");
BufferedInputStream bin = new BufferedInputStream(fin);
BufferedOutputStream bout = new BufferedOutputStream(out);
int ch =0; ;
while((ch=bin.read())!=-1)
{
bout.write(ch);
}
bin.close();
fin.close();
bout.close();
out.close();
}
}
这是我的servlets程序,它会显示gmail图像。现在我的问题是,如果我点击gmail图像然后它重定向到gmail登录页面。在Servlets中是否有任何可能?我的程序有什么变化。我对我的案子提出了建议。好的答案总会让人感激。
答案 0 :(得分:0)
你不能以你所尝试的方式做你想做的事。在这里,您将在流中发送图像。您要做的是发送一个HTML页面,其中包含指向图像的链接,并将该图像放在href标记内,该图像指向谷歌登录。 (如下)
<html>
<body>
<a href="link to page where you want it to go on click"><img src="path to your image"></a>
</body>
</html>
根据需要在html上方打开记事本或任何文本编辑器副本,并将其保存为具有所需文件名的jsp。
答案 1 :(得分:0)
<a href="Redirect"><img src="gmail.gif"></a>