Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-12-2008, 02:08 PM
hannehomuth's Avatar
Member
 
Join Date: Jul 2008
Location: Sommerfeld (Brandenburg, Germany)
Posts: 35
hannehomuth is on a distinguished road
Servlet should return a jsp page not html
Hello Forum,

I've another question. I'am writing an web application with servlets and jsp. Some of my servlets don't work because they return (or write out) no html rather then jsp content. And this jsp stuff will not be parsed. Maybe a little bit strange thats why here an example

This is the processRequest Method in my Servlet (will be called from doGet or doPost)
Code:
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { out.println("<% String browser = request.getHeader(\"User-Agent\");%>" + "<davisjsp:tree level=\"-1\" text=\"\" script=\"true\" browser=\"<%=browser%>\" />" + "<davisjsp:tree level=\"0\" text=\"Golf\" icon=\"project.png\" leaf=\"false\">" + "<davisjsp:tree level=\"1\" text=\"UP1\" icon=\"project.png\" leaf=\"false\" style=\"WIN\">" + "<davisjsp:tree level=\"2\" text=\"Admin\" icon=\"admin.png\" leaf=\"true\" />" + "<davisjsp:tree level=\"2\" text=\"Konstrukteur\" icon=\"konstrukteur.png\" leaf=\"true\" />" + "</davisjsp:tree>" + "<davisjsp:tree level=\"1\" text=\"UP2\" icon=\"project.png\" leaf=\"false\">" + "<davisjsp:tree level=\"2\" text=\"Admin\" icon=\"admin.png\" leaf=\"true\" />" + "</davisjsp:tree>" + "</davisjsp:tree>"); } finally { out.close(); } }
Like you can see above, there are some additonal taglib used.


Code:
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> <%@ taglib uri="./include/davis-tags.tld" prefix="davisjsp" %> <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <link href="css/layout.css" type="text/css" rel="stylesheet"> <title>AIS DCL</title> </head> <body> <tiles:insertDefinition name="aisdcl.stdView" /> <div id="content" align="left"> <jsp:include page = "projectDetails" flush = "true" > <jsp:param name = "project" value = "<%=request.getParameter("project")%>"/> </jsp:include> </div> <tiles:insertDefinition name="aisdcl.stdViewLast" /> </body> </html>
Here I include the servlet and passing a parameter.


And this is the html code from the shown page which the servlet procuded

HTML Code:
<div id="content" align="left"> <% String browser = request.getHeader("User-Agent");%> <davisjsp:tree level="-1" text="" script="true" browser="<%=browser%>" /> <davisjsp:tree level="0" text="Golf" icon="project.png" leaf="false"> <davisjsp:tree level="1" text="UP1" icon="project.png" leaf="false" style="WIN"> <davisjsp:tree level="2" text="Admin" icon="admin.png" leaf="true" /> <davisjsp:tree level="2" text="Konstrukteur" icon="konstrukteur.png" leaf="true" /> </davisjsp:tree> <davisjsp:tree level="1" text="UP2" icon="project.png" leaf="false"> <davisjsp:tree level="2" text="Admin" icon="admin.png" leaf="true" /></davisjsp:tree> </davisjsp:tree>
Now my question. How can I use some jsp notation in my servlet whichs output will be parsed as jsp. I hope you understand me. I want that the servlet output is parsed again and not only written out. I could ask in an other way. How can I use taglibs in servlets. I hope you understand and will answer me soon.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-12-2008, 05:14 PM
hannehomuth's Avatar
Member
 
Join Date: Jul 2008
Location: Sommerfeld (Brandenburg, Germany)
Posts: 35
hannehomuth is on a distinguished road
Found another Way
Hi @ all,

I've went that way, that I generate that Stuff right in the JSP. It is not the best way, I guess, but the one and only which comes in my mind. It would please me do do this in the servlet, but it seems not to work. (I mean such an jsp will be compiled to a servlet, so it might be the same, but I hate this scriplet notation in the jsp pages).

Here my solution, if somebody has the same question anyday.

Code:
<%@ page import="dataBase.SimulateDBConnector" %> <%@ page import="dataBase.ProjectStructure" %> <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> <%@ taglib uri="./include/davis-tags.tld" prefix="davisjsp" %> <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <link href="css/layout.css" type="text/css" rel="stylesheet"> <title>AIS DCL</title> </head> <body> <tiles:insertDefinition name="aisdcl.stdView" /> <div id="tree" align="left"> <% String structureName = request.getParameter("project");%> <% ProjectStructure ps = SimulateDBConnector.getProjectStructureDetails(structureName);%> <% String browser = request.getHeader("User-Agent");%> <davisjsp:tree level="-1" text="" script="true" browser="<%=browser%>" /> <davisjsp:tree level="0" text="<%=ps.getStructureName()%>" icon="project.png" leaf="false"> <% int i;%> <%for (i = 0; i < ps.getProjects().size(); i++) {%> <davisjsp:tree level="1" text="<%=ps.getProjects().get(i).getName()%>" icon="project.png" leaf="false" style="WIN"> <%for (int j = 0; j < ps.getProjects().get(i).getRoles().size(); j++) {%> <davisjsp:tree level="2" text="<%=ps.getProjects().get(i).getRoles().get(j).getName()%>" icon="admin.png" leaf="true" /> <%}%> </davisjsp:tree> <%}%> </davisjsp:tree> <%--<jsp:include page="projectDetails" flush="true"> <jsp:param name="project" value="<%=request.getParameter("project")%>"/> </jsp:include>--%> </div> <tiles:insertDefinition name="aisdcl.stdViewLast" /> </body> </html>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open html page? smartsubroto New To Java 6 06-17-2008 01:00 PM
How to view applet from html page. jwzumwalt Java Applets 2 11-24-2007 06:21 AM
Fetching HTML content of a Web Page JavaForums Java Blogs 0 11-05-2007 10:00 PM
Need to return to login page once logout peiceonly Suggestions & Feedback 1 08-10-2007 01:18 PM
HTML page bbq New To Java 1 07-05-2007 05:46 AM


All times are GMT +3. The time now is 09:38 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org