RSS

Monthly Archives: April 2016

Example to generate JPG image

<%@ page import="java.awt.image.*,java.io.*,java.awt.*,javax.imageio.*" %>
<%
try
{
	response.setContentType("image/jpeg");
	OutputStream o=response.getOutputStream();
	BufferedImage obj =new BufferedImage(200,200,BufferedImage.TYPE_INT_RGB);
	Graphics2D g=(Graphics2D)obj.getGraphics();
	g.drawString("test",50,50);
	ImageIO.write(obj,"jpg",o);
	
}
catch(Exception e)
{
	System.out.println(e);
}

%>
 
Leave a comment

Posted by on April 6, 2016 in Example

 

Example of Programatic Security

<%@ page import="sun.misc.*" %>
<%! 
public void m1(HttpServletResponse res)
{
	res.setStatus(401);
	res.setHeader("WWW-Authenticate","BASIC realmname=enter username and password");
}
%>
<% 
	String s=request.getHeader("Authorization");
	if(s !=null)
	{
		String encodeddata =s.substring(6);

		BASE64Decoder obj=new BASE64Decoder();
		String up=new String(obj.decodeBuffer(encodeddata));

		String [] arr=up.split(":");
		if(arr[0].equals("ad") && arr[1].equals("ad") ) 
		{
			out.println("Welcome to the page" );
		}
		else
		{
			m1(response);
		}
	}
	else
	{
			m1(response);
	}
%>

 
Leave a comment

Posted by on April 5, 2016 in Example