Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Turning a JSP into a JAVA file

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Thanked 0 Times in 0 Posts

    Default Turning a JSP into a JAVA file

    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:

    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) {
    		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) {
            } catch (MalformedURLException me) {
                System.out.println("MalformedURLException: " + me);
            } catch (IOException ioe) {
                System.out.println("IOException: " + ioe);
            //Process proc = Runtime.getRuntime().exec("./html_compare.ksh");
    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:

    I know I'll need multiple methods. I guess the thing that confuses me are things like:


    Should pageContext be a method and therefore this would be an object of that method?

    Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
    if (locale == null) {
    locale = new Locale(Constants.LOCALE_EN);
    For this what should session, Globals and Constants be? Should they also be separate methods and therefore I'm calling objects?

    Any help here would be greatly appreciated.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: Turning a JSP into a JAVA file

    This thread has been cross posted here:


    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java I/O File code; how to read/write file
    By ryu2le in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 18th, 2011, 05:51 PM
  2. Replies: 10
    Last Post: January 12th, 2011, 05:48 AM
  3. How do you convert a jar file into a java file, how ?
    By auto78900 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 12th, 2010, 12:32 AM
  4. insert(embed) a file object (.txt file) in MS excel sheet using java.
    By jyoti.dce in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 12th, 2010, 08:16 AM
  5. How to change File Type of a File Using java
    By akash169 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: March 31st, 2010, 02:58 AM