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 =…
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 =…
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…
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…
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…
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;…
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…