Can i write Html code inside JSP method???

hi i am newbie to jsp and servlets. i am working on a project where i have to use same html code for two conditions in jsp. my question is can i write that html code inside any method in jsp?? and then can i call that method within that if and else scope. can anyone help me with this??

I don't think that does what you think it does.
<%!
void renderStateSelect(String default) { %>Creates a method with that signature and an open brace...
<select name="state"> puts:
out.println("<select name=\"state\">");
into the _jspService method
<%!
// logic to loop thru states
%>Puts the loop logic after the brace opening up the method renderStateSelect
</select>puts
out.println("</select>");
in the _jspService method
<%!
%>Closes the renderStateSelect method.
So if I do this:
<html>
<body>
<%!
void renderStateSelect(String def) { %>
<select name="state">
<%!
// logic to loop thru states
%>
</select>
<%!
%>
Hello<br/>
<% renderStateSelect("none"); %>
Everybody
</body>
</html>The html output is:
<html>
<body>
<select name="state">
</select>
Hello<br/>
Everybody
</body>
</html> The 'renderStateSelect method does not render the state select. The _jspService method does, in place where the HTML is written in the JSP file.  As another look, the translated servlet looks like this:
package org.apache.jsp;
public final class IsThisOk_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {
void renderStateSelect(String def) {
// logic to loop thru states
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {
    try {
      out.write("<html>\r\n<body>\r\n");
      out.write("<select name=\"state\">\r\n");
      out.write("</select>\r\n");
      out.write(" \r\nHello<br/>\r\n");
renderStateSelect("none");
      out.write("\r\nEverybody\r\n</body>\r\n</html>\r\n ");
}See. Any plain HTML code you put outside of the <%! %> tags is converted to out.printlns inside the _jspService method (in place where they occured in the JSP, not where the method you want to do the rendering is called...)
So unless I completely misunderstood your intent here, this apprach does not work.

Similar Messages

  • How can I write HTML code in this forums

    Sorry but I didn't know where to post this thread.....
    How can I write HTML code in this forums?

    Hello,
    Every piece of code in your post should be wrapped with the forum tags [ code] and [ /code], without the blanks.
    In case of the &lt;a> tag, that is not enough. In this case, you have several options. The most elegant one is to use the entity name for the less-then sign - & lt; - without any spaces. Other options is to add a space between the less-then and the ‘a’ character (and make a note of it) or change the less-then character with a left bracket one.
    When posting code, you should always use the forum preview option, just to make sure the forum software “understood” your code correctly.
    Hope this helps,
    Arie.

  • Can we write scriplet code inside c:forEach /c:forEach

    Hi
    I am having one <c:forEach> tag
    As Given below
    <c:forEach var="holiday" items="${state.holidays}" varStatus="current">
       <tr>
          <td>${holiday.name}</td>
          <td>${holiday.date}</td>
       </tr>
    </c:forEach>now I want to apply SimpleDateFormater on ${holiday.date} before showing it on jsp.
    so
    I need to perform following operation
    SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy" );
    String parsedDate = df.parse(holiday.date);
    So for that code should be some this like this but
    <c:forEach var="holiday" items="${state.holidays}" varStatus="current">
       <tr>
          <td>${holiday.name}</td>
    <%
    SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy" );
    String parsedDate = df.parse(holiday.date);
    %>
          <td>${parsedDate}</td>
       </tr>
    </c:forEach>but here I am not able to get holiday inside my scriplet , how can apply SimpleDateFormat on holiday.date?
    is it possible to write scriplet inside tag?
    Please suggest me any other way if you have?
    Regards,
    Manoj

    Use the fmt:formatDate tag instead. It is based on SimpleDateFormat API.
    http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fmt/formatDate.html

  • Html snippet is not working on iweb 9. i can't write a code, Html snippet is not working on iweb 9. i can't write a code

    Html snippet is not working on iweb 9. i can't write a code, Html snippet is not working on iweb 9. i can't write a code

    You don't get this window when you insert an HTML snippet on the page?
    Click to view full size
    If you don't try the following:
    delete the iWeb preference files, com.apple.iWeb.plist and com.apple.iWeb.plist.lockfile, that resides in your Home() /Library/Preferences folder.
    go to your Home()/Library/Caches/com.apple.iWeb folder and delete its contents.
    Click to view full size
    launch iWeb and try again.
    OT

  • Where i shall write html code in jdeveloper

    Hello,
    please tell me where i can write html code in jdeveloper.
    Thanks

    Hi catalina,
    Html tags should not be used directly inside ADF faces pages which may lead to some undesirable results instead you can use ADF Faces tags itself using which you can do what ever you wanted to do with html tags.
    If you still need to use html tags, you can use ADF Faces html tags.
    Tag doc: http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/exchange/jsf/doc/tagdoc/html/index.html
    Sireesha

  • How to write html code in narrative

    Hi,
    How to write html code in narrative to get following format
    desc value1 Value2 totalvalue
    a 10 20 30
    b 20 30 50
    Totalvalue 30 50 80
    Total % 0.3 0.5 0.8
    Can any one help guide on writing HTMl code for above table format in narrative type of display data at report level
    Thank you
    Manu

    Hi Balu,
    If you are using the Web Application server (WEBAs), Then you can create applications using BSP( Bussiness server pages). Which is some what luike JSP.
    Or
    In SE80 , Try to create internet service files uisng BHTML. In the dropdown select internet service. And then try to create the HTML templates
    Thanks,
    Sarayoodharan.K

  • Can I import HTMLs from inside the project and use as portlet page ?

    As you know, I am using Java Studio Creator 2 Update 1 for my current portal project. I have created JSR-168 JSF Portlet Project for my portlet development.
    As I have some html pages ready for my development,
    Can I import HTMLs from inside the project and use as portlet page for my project?
    I did the followings steps:
    1: In side the project - File -> Add Existing Item -> Web Page ( imported test.html page from my local folder)
    2: Let it convert some of the tags for me ( so now it becomes - �test.jsp� )
    3: Set it to initial view.
    4. A default portlet page � newPortletPage.jsp is still there with no initial view.
    Now after doing this, No Visual Designer and Properties window available to for that �test.jsp� page. Though it allowed me to �build� the project successfully.
    When I build and run the portlet application, got the error message �Error occurred in portlet!� on Pluto Portal. Please advice.

    You do not open fcpproject files. You don't double click or anything else. The files have to be in the correct folder structure in the Final Cut Projects folder and the application opens them automatically. Can you post screen shots of the Final Cut Projects folder and its location.

  • Write HTML code in webdynpro

    Hi All,
      Can anyone tell me how two to write HTML code in
      webdynpro application
    to make myself clearer. this is what i want.
    IWDTextView txt = (IWDTextView) view.createElement(IWDTextView.class, "txt" );
    txt.setText("<hr>" + "Today Order");
    But the above code is displaying literal string <hr> by the mean of &lt;HR&gt;
    regards
    Arun

    Hi Nibu,
      What I actually want to do is that- I have designed
    a view having order details one below other on same screen.
      What I want is to print the order detail page wise.
    i.e Ist Orderdetail on first page , 2nd Order detail on 2nd page and so on.....that is I want a page break.
    I got a code to provide a page break which is in javascript -
    <script>
    //<!--
    document.write("hi");
    document.write("<p style=\"color: blue; page-break-before: always\" >");
    document.write("hiafter");
    //-->
    </script>
    How 2 use this code in my webdynpro application.....or
    is there any other mean to do so.
    regards
    Arun

  • Servlet with no dynamic code inside jsp pages

    Hello,
              I saw that a servlet is created even if there is no dynamic code inside jsp pages (scriplets & tags). Is it possible to avoid it on bea side ? (I am using portal 8).
              By the way, do you know if is it possible to define apache in order to avoid to send to bea the jsp which have no dynamic code inside ?
              thank you !

    JSP's always generate a servlet on all web containers. Apache/Tomcat is no
              different. If you have static content, make it an HTML page.
              Bill
              "hournon jc" <[email protected]> wrote in message
              news:22255787.1103297053148.JavaMail.root@jserv5...
              > Hello,
              >
              > I saw that a servlet is created even if there is no dynamic code inside
              jsp pages (scriplets & tags). Is it possible to avoid it on bea side ? (I am
              using portal 8).
              >
              > By the way, do you know if is it possible to define apache in order to
              avoid to send to bea the jsp which have no dynamic code inside ?
              >
              > thank you !
              

  • Can i have html code for date select options (SEARCH HELP)

    Hi frinds,
    I have a BSP Page with input as date.
    Can i have html code for date select options (SEARCH HELP)
    Moosa

    Hi
    Please find the sample code below.
    FROM DATE
          <htmlb:inputField id        = "dd"
                            width     = "45%"
                            type      = "DATE"
                            showHelp  = "X" <- Search help
                            alignment = "CENTER"
                            maxlength = "10"
                            disabled  = "TRUE"
                            value     = "<%= w_FROMDATE %>" />
    TO DATE
          <htmlb:inputField id        = "dd"
                            width     = "45%"
                            type      = "DATE"
                            showHelp  = "X"
                            alignment = "CENTER"
                            maxlength = "10"
                            disabled  = "TRUE"                      
    value     = "<%= w_TODATE %>" />
    Thanks
    kalyan

  • How can we write the code for opening the command prompt and closing the

    how can we write the code in java for opening the command prompt and closing the cmd prompt from eclipse (cmd prompt should close when click on the turminate button in eclipse)

    rakeshsikha wrote:
    how can we write the code for opening the command prompt and closing theBy typing in Eclipse (which you seemingly have)?

  • How can i write the code in xml publisher desktop

    hi all
    How and where can i write the code in xml publisher desktop ???
    shall i know how to write xml code or what ??
    in which part can i write the code if i have more than one query ?

    hi dear
    Thanks for ur replay...
    What i mean is : i used to work on reports builder,so :
    1- i used to create more than query in some reports.
    2- create formulas ,procedures....
    NOW i want to create the same reports by using xml publisher desktop, so how can i do that...
    when i use {color:#ff0000}report wizard{color}, i can not or i don`t know how to use more than one query, create formulas or procedures.
    Please help me.
    Thanks again.

  • How can i write a code to get sume of value from days.

    Hi,
    how can i write a code to get the sum of value of days(example 1 to 30).
    This is in BPS ...
    i created multi planning area and creted planning function with {keyfigure name,planning area,days}.
    now i want to read all the actual values  from basic planing area(basic cube) and calculate the sum of the value.if you have idea can you share the code.
    ENTRIES = VARC ( 'zvardays' ).     ex(zvardays like 28 days or 29 days or 30 days or 31 days)
    COUNT = ENTRIES.
    *Get the all the days value from actual
    FOREACH PAREA = 'basic planning area'.
      COUNT = 1.
    DO
         SUM = SUM + {amount, count}      (amount is a keyfirgure value)
    ENDDO.
    COUNT = COUNT+1.
       SUMACT =  SUM.
    ENDFOR.
    can you correct the above code ....to read the values and sum of the those value.
    Thanks...

    Hi ..
    That is ok..
    Can you provide sample code for my requirement..
    and also how can i pass the error message (can you help me syntax )
    and if my acutal-total  is not equal to plan-total  then
    i have to pass the error message and then  i have to restrict save the data  how i can i restrict(user can not save the data until the values should be equal) .
    Can you help me it is very urgent..
    thanks.//
    Edited by: Eyda rose on Jun 4, 2008 9:29 PM

  • Can't access HTML code in Eloqua

    I want to enhance the functionality and looks and mobile email template. For that I am trying to access HTML Editor to modify HTML code. How can I edit HTML codes in Eloqua10?

    Hello Hammad,
    When it comes to email mobile templates, the feature that makes them a mobile template is the CSS code that can be accessed by going to the toolbox as demonstrated below:
    What this means to you is the following:
    While you cannot access the full source code of this email -- because it is a templated email and not an html uploaded email, you have two options to customize it:
    1) You can delete ALL the contents that come with the template -- the default image and text, and then add your contents to it.
    2) You can upload an email and use the css code that appears in the screenshot above.
    Hope this helps.
    Thanks,
    Tarek

  • Can i write some code in the Debugger

    Dear,
    Can we write some code at the time of debugging.
    For ex. In Production my code is c = a + b.
    now i want  c = a - b.
    <Modified subject line>
    Moderator Message: Please use more descriptive subject lines in future.
    Edited by: Suhas Saha on Nov 17, 2011 12:27 PM

    Hi Anuj,
    First, even I would like to stress the point mentioned above by Suhas. No matter how critical the issue is & even if you have these rights in Production, do NOT change the values in Production system. NOT RECOMMENDED AT ALL.
    About your question of activating from the debugger:
    The De-bugger only opens the source code in a New Window. Till you execute the existing code or activate it from the ABAP EDITOR, your code remains the same. As you are in Production you will have to trnasport the changes after activating the code with the changes.
    Regards,
    Pranav.

Maybe you are looking for

  • SSRS 2008 R2 Report - Sum Totals of a Filtered Group

    I'm at a loss here, so any help will me much appreciated. I will do my best to explain, but if you need additional information, please let me know: I have a very large dataset of patient data. Specifically for the numbers I need, I have a patient num

  • Ability to save data on fillable pdf within a broswer

    I am not sure if this is the right place to post, please let me know if it is not. I make forms for internal use at my company, and most people tend to fill in forms via browser.  Ever since my department has upgraded to CS5 from CS3, nobody could sa

  • LGWR: Archivelog for thread 1 sequence 9339 will NOT be compressed

    Following is a meesage in db01_lgwr_9265.trc *** 2007-08-03 05:37:19.254 LGWR: Archivelog for thread 1 sequence 9335 will NOT be compressed *** 2007-08-03 05:52:38.565 LGWR: Archivelog for thread 1 sequence 9336 will NOT be compressed *** 2007-08-03

  • Superscripts/Subscripts Not Available in Tables?

    I've noticed that I cannot format text as a superscript/subscript if the text is in a cell of a table. Once the cell loses focus, the text goes back to plain old default format. Is there something I should be doing? My workaround thus far has been to

  • Help debugging a PHP open_basedir error. [phpBB3]

    [phpBB Debug] PHP Notice: in file /includes/acp/acp_language.php on line 1123: file_exists(): open_basedir restriction in effect. File(./../language/index.htm/iso.txt) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) Doin