How to use html tags inside java

I have to retrieve data from db and return the data to my index.jsp page.
Its working fine.
But I have o display in a pable format using html. How to embed html tags? I tried this way. Its not working. Any suggestions?
   String htmlOpen = "<html>";
    String htmlEnd = "</html>";
    String titleOpen ="<title>";
    String titleEnd ="</title>";
    String bodyOpen = "<body>";
    String bodyEnd = "</body>";
    for (int i = 1; i <= cols;i++){
        output = output + rsmd.getColumnName(i);
     while (rst.next()) {
        for (int i = 1; i <= cols;i++){
                  output = output +rst.getString(i);
  result = htmlOpen + titleOpen + titleEnd + bodyOpen + output+ bodyEnd + htmlEnd;
    stmt.close();
    conn.close();
     return htmlOpen;
  }

See those charcters in your JSP that look like "<%"? Those characters mean: "the code after this is Java - interpret it as such".
Then when you close your Java block with "%>", it then means: "the code after this is html - output it to the request response that is being built. However, within the html code, the syntax "<%= java_variable_name %>" means "take the current value of that Java variable and insert it into the html output".
Here's an example:
%>
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<%
    String s = null;
    for (int i = 1; i <= ncol; i++)
      s = rsmd.getColumnName(i);
%>
  <th nowrap><A HREF="<%=sortLink.toString()%>&sortby=<%=s%>"><%= s %></th>
<%
%>
</tr>
<%
    if (rs == null || numRows <= 0)
      %><tr><td colspan="10" nowrap>No data available for specified query.</td></td><%
    else
      int rowCounter = 0;
      while(rs.next() && rowCounter < PAGE_SIZE)
        rowCounter++;
%>
  <tr><%
        for (int i = 1; i <= ncol; i++)
          s = rs.getString(i);
          if (rsmd.getColumnName(i).equalsIgnoreCase("password"))
                %><td nowrap>********</td>
<%
          else
            %><td nowrap><%= s %></td>
<%
        %></tr><%
%>
</table>This is JSP 101, what they teach in the first hour of class...
Here's a decent JSP tutorial:
http://www.jsptut.com/

Similar Messages

  • How to use HTML tags inside JSF pages

    I am creating a Menu using dataTable and outputLink in a JSF page.
    <div class="bodyarea">
    <div id="location">
    <ol>
    <h:dataTable value="#{menuItem.breadCrumb}" var="bread" >
    <h:column>
    <li>
    <h:outputLink id="crumbID" value="#{bread.menuLink}">
    <h:outputText id="crumpName" value="#{bread.menuLabel}" style="width: 165px;"/>
    </h:outputLink>
    <li>
    </h:column>
    </h:dataTable>
    </ol>
    </div>
    </div>
    I want to use <li> HTML tag as shown in code above before and after every <tr> tag formed, but when i run it and see view source, this is how it shows:
    NOTE: you can see it has thrown out of <table> tag itself.
    <div class="bodyarea">
    <div id="location">
    <ol>
    <li>
    </li>
    <table>
    <tbody>
    <tr>
    <td><a id="_id0:0:crumbID" href="/eApps/admin/loginPage.jsp?MenuItem=-1"><span id="_id0:0:crumpName" style="width: 165px;">Home</span></a></td>
    </tr>
    <tr>
    <td><a id="_id0:1:crumbID" href="/eApps/admin/loginPage.jsp?MenuItem=3~-1"><span id="_id0:1:crumpName" style="width: 165px;">HIM Admin</span></a></td>
    </tr>
    </tbody>
    </table>
    </ol>
    </div>
    </div>
    Can some one help me, how do i use HTML tags inside <h:dataTable>.
    Or is their any other way i should form my Menus, to fully utilize to HTML tags.
    Thanks
    Ravi

    Hello,
    You can embed the verbatim elements in your datatable, ie,
    <h:dataTable value="#{menuItem.breadCrumb}" var="bread" >
      <h:column>
        <f:verbatim><li></f:verbatim>
        <h:outputLink id="crumbID" value="#{bread.menuLink}">
          <h:outputText id="crumpName" value="#{bread.menuLabel}" style="width: 165px;"/>
        </h:outputLink>
        <f:verbatim></li></f:verbatim>
      </h:column>
    </h:dataTable>

  • How to use HTML Tags in webdynpro java

    Hi,
         Can any body tell me how to use HTML Tags in webdynpro java.
    If u provide me with sample code it will become more usefull.
    Thanks & Regards,
    SN

    HI,
    Please find the steps:
    Create a html file and store in your webdynpro project
    Add the html contents in your file
    & Create a IFRAME UI element and refer you html file
    Now you able to see the html in webdynpro
    Thanks & Regards,
    Ram

  • How to use HTML Tags in Smartforms

    Hi,
    Can you please help me out in knowing how to use HTML tags in Smartforms,
    suppose i want to display some text in BOLD i should use the tag </b> as shown
    </b>  Header Information <b>
    regards
    Ranveer

    Hi Ranveer ,
        check this following links,
      hope this wil helps you
    <a href="http://sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20code%20samples/smartforms/smartform%20in%20abap.pdf">check this link,to know abt HTML in smartforms</a>
    rgds,
    shan

  • How to insert html table inside java code

    Hi,
    I want to send an email with data in table format(with rows and columns) .Please tell me how to achieve this in java code .I just want to know the code for making the table in java
    Please help me
    Thanks in advance

    NewUser7 wrote:
    Please tell me how to generate html tables in java. .. Do you know how to produce an HTML table in HTML?
    ..i dont have jspI did not mention JSP. Pure J2SE code can produce HTML, though if done in a web-app., it would generally be done using JSP or Servlets.
    Here is an example of producing HTML in J2SE.
    import javax.swing.*;
    class HtmlTable {
         public static void main(String[] args) {
              int[][] values = {
                   {1,3894,5387},
                   {2,4112,4459},
                   {3,4886,6076}
              String prefix = "<html><body><table>\n";
              final StringBuilder sb = new StringBuilder(prefix);
              sb.append("<tr>");
              sb.append("<th>");
              sb.append("Month");
              sb.append("</th>");
              sb.append("<th>");
              sb.append("Unit A<br>Sales");
              sb.append("</th>");
              sb.append("<th>");
              sb.append("Unit B<br>Sales");
              sb.append("</th>");
              sb.append("</tr>\n");
              for (int ii=0; ii<values.length; ii++) {
                   sb.append("<tr>");
                   for (int jj=0; jj<values[ii].length; jj++) {
                        sb.append("<td>");
                        sb.append("" + values[ii][jj]);
                        sb.append("</td>");
                   sb.append("</tr>\n");
              sb.append("</table>");
              sb.append("</body>");
              sb.append("</html>");
              Runnable r = new Runnable() {
                   public void run() {
                        JOptionPane.showMessageDialog(
                             null,
                             new JTextArea(sb.toString(),20,10) );
                        JOptionPane.showMessageDialog(
                             null,
                             new JLabel(sb.toString()) );
              SwingUtilities.invokeLater(r);
    As an aside, those terms are HTML (an abbreviation) Java (a proper name) & JSP (an abbreviation). Please try to use correct upper/lower case when using technical terms.

  • How to use HTML parameters in Java applet

    Hello
    In perl I have created a form with things like a selectiuon box called currency and text fields called product for example. Then when I click submit the perl program can pick up the currency and product parameters.
    I have read about applet param eg <param name="param1" value="Apple"> is this the same thing? Or is it different?
    Can I use HTML parameters or do I need to use applet param? I am confused.
    If applet param is what I need, then how do I change the param values say by editing text in a text field?

    You will need to use Java Native Interface JNI. Ther are many posts on the subject, please search, and this is the documentation:
    http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/jniTOC.html

  • How to use html Tags from MySQL with PHP

    I like HTML tags like <b>bold</b> or <BR>
    and others placed in the MySQL database and used by PHP to show up
    in my pages but I don't succeed. I tryied HTML encode
    (htmlentities) from the bindings POP-up menu but nothing happened.
    What is the way this should be acomplished and where is HTML
    encode (and the others in the pop-up menu) being used for?
    Any help will be appreciated,
    Jos

    arnhemcs wrote:
    > I like HTML tags like
    bold or <BR> and others placed in the MySQL
    > database and used by PHP to show up in my pages but I
    don't succeed. I tryied
    > HTML encode (htmlentities) from the bindings POP-up menu
    but nothing happened.
    Just store the HTML as plain text in your database. Using
    htmlentities()
    turns < into &lt; and so on. Using it is what's
    preventing your HTML
    from displaying correctly.
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

  • How to add raw HTML tags inside JSF tags...

    Hi
    I would like to use <input type = text > inside my project in some area..The following code hides the input = type html tag and forwards the click event to jsf command button...After selecting the file,it should forward the value to jsf textfield....
    My code seems as below.
    <h:form id="detailForm" onsubmit="printElements(detailForm,this)">
    <f:verbatim>
    <input id="uploadFile" type="file" style ="dispaly:none"size="100" />
    </f:verbatim>
    <h:inputText id="docName" style="width:650px;" maxlength="100"/>
    <h:commandButton id="visibleBrowseButton" value="Select File..." onclick="'detailForm:uploadFile'.click();callClick();">
    </h:commandButton>
    </h:form>
    <script type="text/Javascript">
    function callClick()
    var val = document.detailForm.uploadFile.value;
    document.getElementById('detailForm:docName').value = val;
    </script>
    While running this page it works fine in IE but in Mozilla firefox it troubles me during detailForm:uploadFile'.click().
    I suspect the jsf page cannot able to detect the raw html tag inside jsf tags...Eventhough i tried using inside<f:verbatim> it wont works..
    I would like to know
    1.Whether the code is right,,if the code goes wrong why it got runned in IE not in firefox....
    2.How can raw html tags can be integrated inside JSF tags....

    First of all, why are you ignoring valuable answers about a JSF fileupload component in your previous topic?
    Second, you can just nest raw HTML anywhere in your JSF page. Your problem is rather related to JavaScript. It has completely nothing to do with Java nor JSF. Learn JavaScript -there is a nice tut at w3schools.com- and look for a JavaScript forum if you still stucks. There are ones at webdeveloper.com and dynamicdrive.com.
    The f:verbatim is only required if you was using JSF 1.1 or older, which is not the case. You would have occurred completely different problems.

  • I want to display BLOB image in JSP Using  html tags IMG src=

    GoodAfternoon Sir/Madom
    I Have got the image from oracle database but want to display BLOB image using <IMG src="" > Html tags in JSP page . If it is possible than please give some ideas or
    Send me sample codes for display image.
    This code is ok and working no problem here Please send me code How to display using html tag from oracle in JSP page.
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="javax.swing.ImageIcon;" %>
          <%
            out.print("hiiiiiii") ;
                // declare a connection by using Connection interface
                Connection connection = null;
                /* Create string of connection url within specified format with machine
                   name, port number and database name. Here machine name id localhost
                   and database name is student. */
                String connectionURL = "jdbc:oracle:thin:@localhost:1521:orcl";
                /*declare a resultSet that works as a table resulted by execute a specified
                   sql query. */
                ResultSet rs = null;
                // Declare statement.
                PreparedStatement psmnt = null;
                  // declare InputStream object to store binary stream of given image.
                   InputStream sImage;
                try {
                    // Load JDBC driver "com.mysql.jdbc.Driver"
                    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                        /* Create a connection by using getConnection() method that takes
                        parameters of string type connection url, user name and password to
                        connect to database. */
                    connection = DriverManager.getConnection(connectionURL, "scott", "root");
                        /* prepareStatement() is used for create statement object that is
                    used for sending sql statements to the specified database. */
                    psmnt = connection.prepareStatement("SELECT image FROM img WHERE id = ?");
                    psmnt.setString(1, "10");
                    rs = psmnt.executeQuery();
                    if(rs.next()) {
                          byte[] bytearray = new byte[1048576];
                          int size=0;
                          sImage = rs.getBinaryStream(1);
                        //response.reset();
                          response.setContentType("image/jpeg");
                          while((size=sImage.read(bytearray))!= -1 ){
                response.getOutputStream().write(bytearray,0,size);
                catch(Exception ex){
                        out.println("error :"+ex);
               finally {
                    // close all the connections.
                    rs.close();
                    psmnt.close();
                    connection.close();
         %>
         Thanks

    I have done exactly that in one of my applications.
    I have extracted the image from the database as a byte array, and displayed it using a servlet.
    Here is the method in the servlet which does the displaying:
    (since I'm writing one byte at a time, it's probably not terribly efficient but it works)
         private void sendImage(byte[] bytes, HttpServletRequest request, HttpServletResponse response) throws IOException {
              ServletOutputStream sout = response.getOutputStream();
              for(int n = 0; n < bytes.length; n++) {
                   sout.write(bytes[n]);
              sout.flush();
              sout.close();
         }Then in my JSP, I use this:
    <img src="/path-to-servlet/image.jpg"/>
    The name of the image to display is in the URL as well as the path to the servlet. The servlet will therefore need to extract the image name from the url and call the database.

  • How to use custom tag in jsp

    sir
    plz tell me how to use custom tag in jsp.plz describe it.
    i will be thankful to u

    Do you want to use taglibs or develop custom tags? Either way take a look at these:
    http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags.html
    http://www.stardeveloper.com/articles/display.html?article=2001081301&page=1
    http://www.onjava.com/pub/a/onjava/2000/12/15/jsp_custom_tags.html
    http://jakarta.apache.org/taglibs/tutorial.html
    http://www.ibm.com/developerworks/edu/j-dw-java-custom-i.html
    http://www.herongyang.com/jsp/tag.html

  • Unable to use HTML tags in the BPEL email component

    Hi,
    I am using BPEL email component to send mail notifications. I want the email should be in proper format.If I use HTML tags the workflow application build fails .It says invalid syntax for html tags.So, I removed the tags and just using the concat string operations as of now.To format i even tried '\n' like in java but it didnt help. Could you please let me know how do I achieve this?
    The JDeveloper version is 11.1.1.3 and SOA ,OIM both are 11.1.1.3
    The BPEL source code for the email content I configured is:
    <copy>
    <from expression="concat(string('AD Account access request has been rejected by manager.\n
    Here are some details about the request:\n
    Request ID : '), bpws:getVariableData('inputVariable','payload','/ns3:process/ns4:RequestID'),string('\n'),
    string('Employee First Name : '),bpws:getVariableData('empFName'),string('\n'),
    string('Employee Last Name : '),bpws:getVariableData('empLName'),string('\n'),
    string('Manager Employee ID : '),bpws:getVariableData('manager'),string('\n\n\n'),string('Thanks,\n IDM Administration')
    )"/>
    <to variable="varNotificationReq"
    part="EmailPayload"
    query="/EmailPayload/ns15:Content/ns15:ContentBody"/>
    </copy>
    Please suggest .
    Thanks,
    Piyasa

    Hi
    Here is the sameple email from BEPL email component. See if this helps:
    "<html>&#x0A;<body>&#x0A;<p>This is an automated message from the <b>Identity Provisioning Solution</b>. Please don’t reply to this email.</p>&#x0A;&#x0A;<p>An access request has been successfully submitted for <%concat(bpws:getVariableData('inputVariable','payload','/ns3:process/ns4:BeneficiaryDetails/ns4:FirstName'),' ',bpws:getVariableData('inputVariable','payload','/ns3:process/ns4:BeneficiaryDetails/ns4:LastName'))%> to access <%bpws:getVariableData('inputVariable','payload','/ns3:process/ns4:ObjectDetails/ns4:name')%>.</p>&#x0A;&#x0A;To view additional details of the request, login to the Identity Provisioning Solution.&#x0A;&#x0A;<br>Request ID: <%bpws:getVariableData('inputVariable','payload','/ns3:process/ns4:RequestID')%>&#x0A;<br>&#x0A;<br>&#x0A;<br>&#x0A;<br>Thank you,&#x0A;<br>Identity and Access Management&#x0A;</body>&#x0A;</html>&#x0A;"
    Regards
    user12841694

  • How to use custome tag lib in the JSP page?

    How to use custome tag lib in the JSP page?...with JDeveloper

    http://www.oracle.com/webapps/online-help/jdeveloper/10.1.2/state/content/navId.4/navSetId._/vtTopicFile.working_with_jsp_pages%7Cjsp_ptagsregistering~html/

  • How to use nested tag in Struts

    Hi..
    Can any one guide me how to use nested tag in Struts. So far i already tried bean tag with no error but when i try to use nested tag i got error like
    javax.servlet.ServletException: Cannot find bean: "" in any scope
    Below are my class:
    action class
    session.setAttribute ("MyDetailList", detailList);
    JSP page
    <logic:iterate id="list" name="MyDetailList">
    Company ID : <bean:write name="list" property="companyID" />
    </logic:iterate>
    For bean tag, i got no error at all and below are my code for nested tag
    action class
    session.setAttribute ("MyDetailList", detailList);
    JSP Page
    <nested:nest property="MyDetailList">
    Make : <nested:text property="make"/>
    Car ID : <nested:text property="carID"/>
    </nested:nest>
    When i run the code, i got error message
    javax.servlet.ServletException: Cannot find bean: "" in any scope
    Any body can help me?
    zul

    what am I doing wrong?You will notice above that I mentioned
    YOU CAN'T USE CUSTOM TAGS AS ATTRIBUTES TO OTHER CUSTOM TAGS
    (was that loud enough for you to notice this time)?
    Try
    <html:text styleId="instruction" styleClass="text" size="50" name="instruction" property="value"/>
    //or
    <html:text styleId="instruction" styleClass="text" size="50" property="instruction" value="<%= instruction.getValue() %>"/>
    better alternative: populate your formbean with your action and just have:
    <html:text styleId="instruction" styleClass="text" size="50" property="instruction"/>
    If you set the "instruction" property of your formBean in the action, the value will be automagically reflected here.
    Cheers,
    evnafets

  • How To Call HTML Page Through Java Swing Page  ???....

    Hi All ;
    Please Can You Tell Me How To Call HTML Page Through Java Swing Page ....
    Regards ;

    Hi,
    you can use HTML fragments on a panel.
    http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
    However, to integrate a browser you need 3rd party software like IceBrowser
    If you Google for: HTML Swing
    then you find many more hints
    Frank

  • Embed HTML tag inside XSLT to generate email content

    I want to Embed HTML tag inside XSLT to generate email content .
    XSLT is not working in Jdeveloper , when i use the syntax <xsl:output method="html" indent="yes" version="1.0"/> in transformation activity .
    Can anyone help to resolve the issue .

    in the <xsl:template match=""/> element you can just start with creating your html document
    so for example
         <xsl:template match="/">
              <html>
    the graphical mapper itself won't i think but when you test the xsl it will still procedure a html document, we use it too to generate the email body contents

Maybe you are looking for

  • New to Java Wireless Programming - Help needed!

    I'm currently finishing my 4 java programmign class in university, and i'm not looking to expand my knowledge in the this language. I would like to learn the how to code for wireless devices. I've already downloaded the Java Wireless Toolkit, but I w

  • I did a software update on my ipad and now cannot access the internet. how can i fix this?

    I did a software update on my ipad to 8.1 and now cannot access the internet.  How do I fix this?  My mail updates, but to get internet access I had to move from wifi to cellular data, and now even cellular data does not allow me access.

  • Cannot update QuickTime

    I am trying to install the new version of Quick Time and iTunes but the i keep on getting an error message saying that the HKEY_LOCAL_MACHINE\Software\Classes\QuickTime.Quic kTime\CLSID. key cannot be unlocked. I have never adited anything with the R

  • FM to display Application Log

    Hi All, Can you kindly suggest me any Function Module through which I can get to view the Application Log . The Most Important Requirement is it should be for the particular user who is accessing it and not for anyone else. I have tried APPL_LOG_DISP

  • I need to reset an unknown password(s).

    I have an unusual situation here. We recently discovered that a person here had a database running on a workstation that was located under his desk in his office. Nobody knew about this computer. The database was believed to be running on a server in