Best practices with Servlets and JSPs [message #142913] |
Sat, 08 October 2005 11:59 |
Eclipse User |
|
|
|
Originally posted by: googgooo.gmail.com
Hi all,
I'm new to JSP world and am still playing with the basics. Feel free to
direct me to a different newsgroup or mailing list if I'm offtopic here ;-)
I've got some questions about the "best practices" for web applications:
1) I'm doing all the app logic in Servlets and want the results
presented in JSP pages. How do I pass the data from Servlet to JSP?
- I came across getRequestDispatcher("something.jsp").forward() calls
but passing everything in URL parameters looks odd to me.
- I thought about generating the results into a XML output in the
servlet, fetch it from the JSP via <c:import url="/TheServlet"
var="xml"/> and then process using standard JSTL tags.
- Or should I instead write a XSLT templates and transform the XML
output directly into XHTML?
- I was as well thinking about creating lots of custom Tags to display
various parts of the webpage. Afterall is this a way to go?
What would you recommend?
2) I'm about to distribute the webapplication as a standalone WAR file
with config.jsp that will ask some questions from the user and store the
answers. My question is where to save the output from such page? I could
save almost everything in a database, but before that I need to read the
database credentials (hostname, dbname, username, password) from
_somewhere_. What's the common way to do this? Save a config file under
WEB-INF?
Thanks!
Goo
|
|
|
Re: Best practices with Servlets and JSPs [message #142990 is a reply to message #142913] |
Mon, 10 October 2005 08:03 |
Eclipse User |
|
|
|
Originally posted by: wknauf_NO_._INSIDE_hg-online.de
Hi !
Goo G. Gooo wrote:
> 1) I'm doing all the app logic in Servlets and want the results
> presented in JSP pages. How do I pass the data from Servlet to JSP?
You can put any data in the request as key-value-pairs, just like in a
hashtable. So to pass some Integer value to the JSP, do this in the servlet:
request.setAttribute("myIntegerValue", new Integer (10) );
In the JSP you can get it out of the request:
Integer intValue = (Integer) request.getAttribute ("myIntegerValue")
>
> 2) I'm about to distribute the webapplication as a standalone WAR file
> with config.jsp that will ask some questions from the user and store the
> answers. My question is where to save the output from such page? I could
> save almost everything in a database, but before that I need to read the
> database credentials (hostname, dbname, username, password) from
> _somewhere_. What's the common way to do this? Save a config file under
> WEB-INF?
You could add the parameters to your web.xml.
<servlet>
<servlet-name>Some Servlet</servlet-name>
<init-param>
<param-name>parameter</param-name>
<param-value>5</param-value>
</init-param>
</servlet>
Hope I could help
Wolfgang
|
|
|
Powered by
FUDForum. Page generated in 0.02992 seconds