Hello, I have a class the purpose of which is to grab the HTML from a given URL or set of URLs that I hardcode in it. I have a JSP that I was given that already does this. I was told that I need to put it in a normal Java file so I can run it and test it and my code can be put where it belongs by another developer. So far I've worked a lot of the kinks out but I'm a little confused by what I got on another forum. Below is my code:
It is giving me some errors on pageContext, session, Globals, Constants, and out saying they cannot be resolved or cannot be resolved to a variable and I was told by extracting a delegate class to do the work you avoid pageContext and session and for the most part you avoid Globals and Constants. They said I would need to create some new methods for this but didn't give much more information to which I asked:import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Locale; public class htmlOutput { /** * @param args */ public static void main(String[] args) { pageContext.setAttribute("enBean","en"); Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY); if (locale == null) { locale = new Locale(Constants.LOCALE_EN); } // Setting the session attribute indicating entry from index page session.setAttribute(Constants.ENTER_FROM_INDEX, new Boolean(true)); URL headerURL; URLConnection headerURLConnection; BufferedReader br; String inputLine; try { headerURL = new URL("*"); headerURL = new URL("*"); headerURL = new URL("*"); headerURLConnection = headerURL.openConnection(); br = new BufferedReader(new InputStreamReader(headerURLConnection.getInputStream())); while ((inputLine = br.readLine()) != null) { System.out.println(inputLine); } } catch (MalformedURLException me) { System.out.println("MalformedURLException: " + me); } catch (IOException ioe) { System.out.println("IOException: " + ioe); }finally{ br.close(); } //Process proc = Runtime.getRuntime().exec("./html_compare.ksh"); } }
I know I'll need multiple methods. I guess the thing that confuses me are things like:
pageContext.setAttribute("enBean","en");
Should pageContext be a method and therefore this would be an object of that method?
Also:
For this what should session, Globals and Constants be? Should they also be separate methods and therefore I'm calling objects?Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY); if (locale == null) { locale = new Locale(Constants.LOCALE_EN);
Any help here would be greatly appreciated.