Win a copy of Rust Web Development this week in the Other Languages 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Servlet output into JSP template

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope this can be done, else I'n gonna hve to rethink things here...

I have a reporting tool which does quite a complicated search (SQL), so rather than have all the workings of the search in a messy JSP, I've dumped it all into a Servlet, which the uses PrintWriter to output the results.

What I really want is for the results to be outputted(is that a word?) to an existing JSP template page.

So it would be great if there was some sort of JSP <% input Servlet results here function %> rather than using a PrintWriter to output the entire page.

Any offers?

Anyone understand a word I just said?
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That' a common thing to do. Processing is performed in a Servlet, the data is attached to the request as a scoped variable (or variables) using the setAttribute() method, and a request dispatcher is used to forward to a JSP page where the data is used to render the view.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
alternatively you can just <jsp:include> the servlet onto a JSP page.
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers for that guys, but how do I actually get the data to the JSP?

I've tried:-
String sCounter = request.getAttribute("counter"); but this causes the following error: Type mismatch: cannot convert from Object to String


So I tried:-
String sCounter = (String)request.getAttribute("counter"); but this causes my Servlet to crash out, displaying a blank browser creen (no errors reported in logs)
 
Bear Bibeault
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Search the logs for the exception causing the "crash out".
 
Because those who mind don't matter and those who matter don't mind - Seuss. 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