Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Turning a JSP into a JAVA file

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

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?

Any help here would be greatly appreciated. Also as a note I have cross posted this on:
http://www.java-forums.org/advanced-java/54448-turning-jsp-into-java-file.html
http://www.javaprogrammingforums.com/whats-wrong-my-code/13596-turning-jsp-into-java-file.html#post55883
 
Ranch Hand
Posts: 137
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The various contexts request, session, etc are part of the servlet specification and available to the JSP because the JSP is compiled to/runs as a servlet. Glancing at your code, I suggest you remove those values (comment out) to see if thd code does what you want. Ultimately you'll want to isolate your code into methods on a class so you could invoke them from a JSP or anywhere else. You may need to work with the line 27 (indication of entry from index page) to see if there is a parameter on the URL you can set for this one.
 
Sean K. Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much after like 3 days it looks like it's working. Any tips on how I can get this to save the HTML file to a location?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic