Wednesday, 5 November 2014

How to Find the Browser information Agent,Cookies,and lot more

Sometimes we want to know about browser information,for some purpose and based on it we want to do some process, for that we must know browser info..like agent, what parameter are coming along with request and so..

We can do by create one web application.
create servlet:--
-----
@WebServlet("/AgentServlet")
public class AgentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
     
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AgentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

Map<String, String> map = new HashMap<String, String>();

Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
map.put(key, value);
}

System.out.println(map);
PrintWriter pw =response.getWriter();
pw.write(map.toString());

 pw.write("\n spcific to user-agent");

 pw.write(request.getHeader("user-agent"));
}
/**
-----------------------------------
create a jspP--

<form action="AgentServlet" method="get">
<table>
<tr><td>ready to see</td></tr>
<tr><td colspan="2"><input id="submit" type="submit"/>
</td></tr>
</table>
</form>
-------------------------
now you can see the info.. 

No comments:

Post a Comment