Outputting xHTML using JSP backend

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reeba
    New Member
    • Mar 2010
    • 5

    Outputting xHTML using JSP backend

    I want to fetch a set of data from the database and display in the form of a table in the mobile console with frontend as xhtml and backend as servlet.

    I tried using the list but got some null pointer exception. I guess its because i cannot use the jsp tags in my xhtml file.

    I also wanted an idea as how to go about with xhtml parsing?
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Could we see how you tried to get the list?
    So your output should just be like a typical xhtml table? eg:
    <table>
    <tr><th>....</th></tr>
    ....
    etc.

    Comment

    • reeba
      New Member
      • Mar 2010
      • 5

      #3
      This is my servlet side code:
      Code:
      String sql = "select c_user_id,c_password from t_gb_user_master";
            Statement s = connection.createStatement();
            s.executeQuery (sql);
            rs = s.getResultSet();
            while (rs.next ()){
              //Add records into data list
              dataList.add(rs.getString("c_user_id"));
              dataList.add(rs.getString("c_password"));
            }
            rs.close ();
            s.close ();
            }catch(Exception e){
            System.out.println("Exception is ;"+e);
            }
          System.out.println("dataList SIze : "+dataList.size());
            request.setAttribute("data",dataList);
            //Disptching request
            RequestDispatcher dispatcher = request.getRequestDispatcher(page);
            if (dispatcher != null){
              dispatcher.forward(request, response);

      and this is xhtml file:

      Code:
      <form action="Test1Servlet" method="Post">
      <table border="1" width="303">
      <tr>
      <td>username</td>
      <td>password</td>
      </tr>
      <%Iterator itr;%>
      <% List data= (List)request.getAttribute("data");
      System.out.println("Data Size : "+data.size());
      for (itr=data.iterator(); itr.hasNext(); )
      {
      %>
      <tr>
      <td><%=itr.next()%></td>
      <td ><%=itr.next()%></td>
      </tr>
      <%}%>
      </table>
          </form>

      the problem is, the jsp tags are getting displayed as it is in the mobile browser... for example (<%=itr.next()% > is displayed as it is in the output table, in the mobile brower)....
      Everything is getting displayed properly in the normal browser...

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Sounds like the file isn't getting processed as a .jsp file. Have you saved it with a .jsp extension? Further, is jsp supported on the browser you're using?

        Comment

        • reeba
          New Member
          • Mar 2010
          • 5

          #5
          Yes ... I have saved my file as a .jsp file and my browser also supports it.
          I am working on a mobile application.
          I jus wanted to fetch the data from the database and put it into an xml file dynamically, and display it in the mobile browser....
          and later if i need to fetch the data I should be able to fetch it from the xml file rather than the database....
          can u help me as to how i can go about with it

          Comment

          • jkmyoung
            Recognized Expert Top Contributor
            • Mar 2006
            • 2057

            #6
            Can you get even simple statements like this to work?
            Code:
            <% 
            System.out.println("JSP is working");
            java.util.Date date = new java.util.Date();
            %>
            The time is now <%= date %>
            Forgive me for asking: but when you say " I have saved my file as a .jsp file" do you mean:
            1. It was always saved as a .jsp file but wasn't working?
            2. You just now saved your file to a .jsp file and the .jsp started working but failing?

            Comment

            Working...