Download a Webpage in Java

public static String downloadFromUrl(String my_url) { URL url; InputStream is = null; BufferedReader br; String line; String content = “”; try { url = new URL(my_url); is = url.openStream(); // throws an IOException br =…

Java: view all the headers in tomcat

Source Code for RequestHeader Example import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class RequestHeaderExample extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType(“text/html”); PrintWriter out = response.getWriter(); Enumeration…

Java Tomcat Session Example

Source Code for Session Example import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class SessionExample extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType(“text/html”); PrintWriter out = response.getWriter(); HttpSession…

Java servlet example for read and create cookies in Tomcat

Source Code for Cookie Example import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class CookieExample extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType(“text/html”); PrintWriter out = response.getWriter(); // print out…

How to save text files in Java with umlauts

Here at .Maui, working in Java on files written in German, we had difficulty saving files that contained umlauts. Here is the solution we found: package javaexample; import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter;…

Set and read cookies within JSP

How to read and create cookies in Java within JSP pages. This example will write the value sel cookie “username”. If the cookie does not exist it will be created and will be visible once…