Results 1 to 2 of 2
  1. #1
    hannehomuth's Avatar
    hannehomuth is offline Member
    Join Date
    Jul 2008
    Location
    Sommerfeld (Brandenburg, Germany)
    Posts
    36
    Rep Power
    0

    Default 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)
    Java 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.


    Java 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

    XML 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.

  2. #2
    hannehomuth's Avatar
    hannehomuth is offline Member
    Join Date
    Jul 2008
    Location
    Sommerfeld (Brandenburg, Germany)
    Posts
    36
    Rep Power
    0

    Default 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.

    Java 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>

Similar Threads

  1. How to open html page?
    By smartsubroto in forum New To Java
    Replies: 8
    Last Post: 08-16-2012, 01:13 PM
  2. Need to return to login page once logout
    By peiceonly in forum Suggestions & Feedback
    Replies: 2
    Last Post: 03-31-2009, 08:50 PM
  3. How to view applet from html page.
    By jwzumwalt in forum Java Applets
    Replies: 2
    Last Post: 11-24-2007, 05:21 AM
  4. HTML page
    By bbq in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 04:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •