JSP / HTML doubt ...

Hi every one!
My doubt may seem to be a waste doubt, but its a doubt,so..,
Can we use JSP tags(like <%,<%=) in a servlet program.
And can we use a JSP tag in between or inside a html tag as.,
<a href=my.html name=<%=val%> >Hi</a> ,,where val is a string object holding some string say Hi.Can we use like this?
Plz guide me! Thnkz in advance...

Yes, like Yogesh mentioned it is possible to include a JSP expression
<%=someVariable%> inside the value attribute of an HTML tag.
However, there is a new and improved way of doing this. In case you are using the latest versions of everything - JSP 2.0 , Servlet 2.4 etc
instead of using a JSP expression like this <%=someVariable%> , now you can do it in a much simpler syntax with EL like this ${someVariable}If you install JSTL 1.1 and configure it , there are much simpler and better ways to do things with JSPs now.
For example this JSP scriptlet :
<%
for (int i=0; i < 10; i++){
    out.println(i);
%>could be written in JSTL inside a JSP as
<c:forEach begin="1" end="10" var="index" step="1">
    ${index} <br/>
</c:forEach>The above is just a small example and doesn't show all the benefits of JSTL, but when the application grows large if one uses just JSP scriptlets and expressions the code becomes unmanageable.
With JSTL the code looks much cleaner , simpler as it encapsulates all business logic to the business layer.
If you are new to JSPs then you can get familiar with scriptlets and expressions, but I encourage you to make use of the benefits of JSTL after you become familiar with the basics of JSPs.
Message was edited by:
appy77

Similar Messages

  • How do you make JSF draw frame in browser w/o JSP & HTML ?

    Hi all,
    I already have small web application which uses HTML & JSP and I want to convert it to JSF based application.
    I've read O'Reilly JSF books written by Hans Bergsten and in Chapter 15 he states that you can use pure Java classes only (without JSP & HTML) in your web application.
    My web application contains some frames. Since I only want to use pure Java classes using JSF what component should I use to draw frame ?
    I use MyFaces implementation of JSF.
    Any advice would be greatly appreciated.
    Best Regards,
    Setya

    I don't know anything about myFaces, but as far as I know, there is no component to draw frames. The JSF book you read is correct to a degree... It's possible to write completely with JSF tags, but it can be cumbersome sometimes.
    To output frame tags using a JSF tag, you can use one of two methods.
    First, you can use the outputText tag with escape attribute set to false.
    <h:outputText value="<FRAMESET blah blah blah>" escape="false" />The second way is to just wrap HTML in f:verbatim tags.
    <f:verbatim><FRAMESET blah blah blah></f:verbatim>If using the second method, be careful not to have any other JSF tags inside the f:verbatim tags.
    Hope this helps,
    CowKing

  • How to convert the source code in JSP,HTML&BEANS into executable files?

    Sir,
    We are developing one s/w product in JSP,HTML&BEANS.Now we are in the implementation phase.During the time of Installation,without copying our source code in the customer's site I want to copy the executable files of the entire source codes? Is it possible in JSP,HTML&BEANS?

    In theory you can do it even with JSP but the you will be unable to run it on the standard JSP engine. :-)
    From other hand, all critical logic should be in the Java Beans or at least in custom tags but not in the JSP code. Then you can protect that code and leave JSP open because there is nothing to steal or break.

  • How to get the size of JSP html output?

    Hi,
    Is there a JSP method to get the size of JSP HTML output.
    e.g. I would like to print the size of the JSP e.g.
    Size of this page is <%=pageContext.getPageSize()%> Kb ???
    Any ideas? Thanks.
    George
    Edited by: googchro on Jan 5, 2010 4:45 PM

    Would you like to print "the size of this page is..." before or after you calculate the size of the page.
    Because adding that bit of text to the page will make the page bigger...
    Doing it in java, the best approach would probably to have a filter counting the number of bytes that gets sent to the writer/output stream.
    A client side tool measuring the amount of bytes received would probably be easier though.
    You can always look at the Content-length header sent with a response. Though you normally don't have access to that on the java/jsp side, as it is sent by the container.
    cheers,
    evnafets

  • Print JSP/HTML Pages (perhaps PDF?)

    Hi,
    i have a table in HTML generated by JSP.
    Just like the following simple example:
    ...<table>
    <%
    for( Enumeration et = free.getSqlIDs().elements(); et.hasMoreElements();)
    String keyt = (String)et.nextElement();
    Bean b = new Bean();
    b.init(path,DB);
    b.setID(keyt);
    b.restore();
    %>
    <tr>
    <td>
    <%out.print(b.getName());%>
    </td>
    <td>
    <%out.print(b.getAdress());%>
    </td>
    </tr>
    %>
    </table>...
    No i want to give a button to the user. When pressed, the HTML-Page should transform to PDF.
    With such a method i want to print the HTML-Page.
    I Know that this is possible with the help of XML/XSP and a stylesheet. But i like to do that with this way:JavaBeans-->JSP-->HTML-->PDF
    Anyone a solution, some code examples for me?
    Or perhaps another solution to print HTML-Pages in a fine design?
    Thank you for your help
    Andy

    Hi,
    no one any idea?
    How do you print Jsp Pages?
    Thank you
    Bye
    Andy

  • Tomcat Vs Weblogic .. jsp/html file path issue..

    Tomcat gurus, please help !!!
    Development Env. :
    OS: Window NT 4.0 SP6
    Web Server: Tomcat 4.1.12
    Sun JDK 1.3.1
    IDE : Eclipse 2.1
    Deployment/Testing/Prod Env:
    OS: Sun Solaris 2.8
    Web Server: Weblogic 5.1 SP 12
    Sun JDK 1.3.1 IDE : N/A
    Confession: New to Tomcat world.
    Note: Reason why I'm using Tomcat for development though I can use Weblogic, Eclipse IDE with Tomcat plugin provides debuging functionality, thus the problem. I have an enterprise application being built and kind of stepped into a problem. I have a Servlet that marshals all the calls and process them through java beans ( about 50+ ) and content displayed through JSPs.
    Here is the directory structure,
    /AppContext
    | +- src
    | +- com.xyz.wfservices
    +- jsp
    main.jsp
    +- WEB-INF
    |
    + classes
    + com.xyz.wfservices ( compiled classes )
    For Weblogic: It has 2 parameters to specify where the compiled code is and where the docs are,
    => weblogic.httpd.servlet.classpath=c:/wfservices/WEB-INF/classes
    => weblogic.httpd.documentRoot= c:/wfservices/src/html
    and to register instance,
    weblogic.httpd.register.WfServices=com.xyz.wfservices.WfSvcsController
    weblogic.httpd.initArgs.WfServices=\
         main.properties=c:/wfservices/src/properties/wfservices.properties
    But, I looked at Tomcat it is quite different.. it has <Context path="/wfs" docBase="L:\app_services\wfservices" workDir="L:\app_services\wfservices\work" /> Servlet def in web.xml
    <servlet>
    <servlet-name>WfServices</servlet-name>
    <servlet-class>com.xyz.wfservices.WfSvcsController</servlet-class>
    <init-param>
    <param-name>main.properties</param-name>
    <param-value>c:\wfservices\properties\config.properties</param-value>
    </init-param>
         <servlet-mapping>
              <servlet-name>WfServices</servlet-name>
              <url-pattern>/WfServices</url-pattern>
         </servlet-mapping>
    </servlet>
    Probem: Accessing JSP/Html ... documents. weblogic accessing / calling jsp ..
         rd = req.getRequestDispatcher("/main.jsp");      //req is HttpRequest
         if (rd != null)
              rd.forward(req, resp);
    The same does not work under Tomcat because it can find files relative to the context, thus it fails. I have to change the code like below to make it work.
         rd = req.getRequestDispatcher("/src/jsp/main.jsp");
         if (rd != null)
              rd.forward(req, resp);
    It is a nightmare now to maintain two different environments and more over changing all the references and and its internal references is not feasible. The question is, is there a way to configure docBase in tomcat so that I won't need a code change.
    Any help or inputs are greatly appreciated.
    Thanks
    Meher

    I ran into this same problem before, so I created a utility class that would map out a URI or URL given a relative path. It's nice because it will detect and include non-standard ports for both the HTTP and HTTPS protocols. If you access a servlet/jsp using HTTP, it will return a URL for the HTTP protocol and the same for HTTPS. So, that means you don't need any code changes to access things through HTTP or HTTPS :) Here it is, hope it helps you out:
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ContextMapper
        private static final int HTTP_PORT = 80;
        private static final int HTTPS_PORT = 443;
         * This method will return a URI to access a resource given its relative
         * path.  Please note that the relative path should start in the directory
         * where the web application is deployed to.
         * @param HttpServletRequest request
         * @param HttpServletResponse response
         * @param String relativePath
         * @return String
        public static String getUri (HttpServletRequest request, HttpServletResponse response, String relativePath)
            return request.getContextPath() + relativePath;
         * This method will return a URL to access a resource given its relative
         * path.  Please note that the relative path should start in the directory
         * where the web application is deployed to.  Also, the protocol will be
         * automatically detected from the request.  Supported protocols include
         * HTTP and HTTPS.  For all other protocols, the relative path will be
         * returned unmodified.
         * @param HttpServletRequest request
         * @param HttpServletResponse response
         * @param String relativePath
         * @return String
        public static String getUrl (HttpServletRequest request, HttpServletResponse response, String relativePath)
            if (request.getProtocol().startsWith("HTTP/") == true)
                switch (request.getServerPort())
                    case HTTP_PORT:
                        return "http://" + request.getServerName() + request.getContextPath() + relativePath;
                    default:
                        return "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + relativePath;
            else if (request.getProtocol().startsWith("HTTPS/") == true)
                switch (request.getServerPort())
                    case HTTPS_PORT:
                        return "https://" + request.getServerName() + request.getContextPath() + relativePath;
                    default:
                        return "https://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + relativePath;
            else
                return relativePath;
    }Here are a few examples of using this class:
    String uri = ContextMapper.getUri(request, response, "/css/basic.css");
    String url = ContextMapper.getUrl(request, response, "/css/basic.css");
    String uri = ContextMapper.getUri(request, response, "/images/image.gif");
    String url = ContextMapper.getUrl(request, response, "/images/image.gif");
    String uri = ContextMapper.getUri(request, response, "/jsp/HelloWorld.jsp");
    String url = ContextMapper.getUrl(request, response, "/jsp/HelloWorld.jsp");
    String uri = ContextMapper.getUri(request, response, "/servlet/HelloWorld");
    String url = ContextMapper.getUrl(request, response, "/servlet/HelloWorld");

  • JSP, HTML, CLASS, JAVASCRIPTS TO EXE OR PACKAGES

    Sir / Madam,
    I am a student, I am learning by myself. Plz help me.
    Can we create a package or exe which contains all JSP , HTML and their corresponding Images and Javascripts. Then extract in the server.
    ie: Server should not contain source code. It should in the form of EXE or other forms.
    Expecting Early replay.
    Thank You,
    Rengaraj

    hI renga_murali, well here is my openion about your thread. Hope you will get what you are looking for exactly.
    JAR files = collection of class files
    WAR files = collection of class, JSP, XML files
    EAR files = collection of JAR, WAR, and EJBs
    There are no structural differences between the files; they are all archived using zip/jar compression. However, they are intended for different purposes.
    Jar files (files with a .jar extension) are intended to hold generic libraries of Java classes, resources, auxiliary files, etc.
    War files (files with a .war extension) are intended to contain complete Web applications. In this context, a Web application is defined as a single group of files, classes, resources, .jar files that can be packaged and accessed as one servlet context.
    Ear files (files with a .ear extension) are intended to contain complete enterprise applications. In this context, an enterprise application is defined as a collection of .jar files, resources, classes, and multiple Web applications.
    Each type of file (.jar, .war, .ear) is processed uniquely by application servers, servlet containers, EJB containers, etc.
    ALSO REFER :
    Creating a JAR File : http://java.sun.com/docs/books/tutorial/jar/basics/build.html
    Creating a WAR File :
    http://access1.sun.com/techarticles/simple.WAR.html
    Creating a EAR File :
    http://access1.sun.com/techarticles/DissectingEARs/DissectingEARs.html
    Threads :
    http://forum.java.sun.com/thread.jspa?threadID=483657&messageID=2258904
    http://forum.java.sun.com/thread.jspa?threadID=455102&messageID=2075155
    Explaination :
    http://www.cezwright.com/tools/java/jar_war_ear.htm

  • Jsp&html urgent

    hello ,
    Im writing a page that uses the ahref attribute to navigate bw two JSP pages and the pages do some queries . i need to process the queries based on the value which the user clicks Can anybody help mw out to pass values in Ahref syntax and capturing it in the next Jsp page
    Thankx

    hello ,
    Im writing a page that uses the ahref attribute to
    navigate bw two JSP pages and the pages do some
    queries . i need to process the queries based on the
    value which the user clicks Can anybody help mw out
    to pass values in Ahref syntax and capturing it in
    the next Jsp page
    ThankxPal,
    u mean u'l hav a link(ie <a href attrib....>) in both the jsp pages..n those queries if done for accessin a database cud b dne bettre using a bean....anyways
    Pls b comprehensive about ur requirements...
    This is whut i thought of :take this code ..hope it'l b of some use..
    empbean.jsp:
    <Html>
         <Body><Center>
         <jsp:useBean id="eb" class="employee.EmpBean" />
         <jsp:setProperty name="eb" property="ename" value="coolx"/>
         <jsp:setProperty name="eb" property="ejob" value='"chief architect"/>
         <H1>
         The Employee Name is set to :
         <jsp:getProperty name="eb" property="ename" />
         <Hr>
         The Employee Job is set to :
         <jsp:getProperty name="eb" property="ejob" />
         </H1>
         </Center></Body>
    </Html>
    2. empbean.java
    package employee;
    public class EmpBean
         private String ename;
         private String ejob;
         public void setEname(String nm)
              ename=nm;
         public String getEname()
              return(ename);
         public void setEjob(String jb)
              ejob=jb;
         public String getEjob()
              return(ejob);
    Hope u kno about beans..if dont , in short a special class with zero parameter constructor and havin accessor and mutator methods to access the bean properties..
    Here this jsp page creates a bean object and passes on the parameters to the bean through bean properties tag..

  • Jsp/html form- servlet- xml parsing

    does anyone have an example or know of a place where I can get code
    which passes XML from jsp/html to servlet which parses the xml???
    will be appreciated..........thanks

    Hi,
    Are u trying to acheive indpendent of browser solution or just want to know the things..
    well,I have one idea ok.
    Using JavaScript Constructs the XmL as u want, "let say
    <root><name>Lokesh</name><age>25</age></root>" before submitting the page(I mean frm.submit()) assign to a hidden variable, since you have post kind of submit back at the servlet from the request object get the value and store it as String and using StringReader you just parse the XML
    Just try the above one the below code
         public org.w3c.dom.Document getXMLDocument() throws IllegalStateException,Exception
                        if (!containsXMLDocument())
                                  throw new IllegalStateException("This request does not contain an XMLDocument");
                   javax.xml.parsers.DocumentBuilderFactory dbf=javax.xml.parsers.DocumentBuilderFactory.newInstance();
                   javax.xml.parsers.DocumentBuilder db=dbf.newDocumentBuilder();
                   java.io.StringReader strRdr=new java.io.StringReader(_xmlString);
                   org.xml.sax.InputSource ipSrc=new org.xml.sax.InputSource(strRdr);
                   org.w3c.dom.Document doc=db.parse(ipSrc);
                   return doc;
    best of luck..
    With Regards
    Lokesh T.C

  • Create Form Beans from JSP/HTML forms

    In the Builder certification objectives, there is one called "Create Form Beans from JSP/HTML forms". How can I do that? How can I create a form beam starting from the JSP form or HTML form?

    Guys, no one from forum can answer this question?

  • Controlling printmargins with java/jsp/html

    I was wondering if there is any way to set the standard margins in browser to 0.
    As for Firefox, the settings for top, bottom and both sides margins are sat to 12,7.
    Is there any way for my application to set this values (including all other browsers as well) to print what I am presenting in my viewing.
    I have a webpage that I want the user to get a "printer friendly" new page which controlles the margins for the print.
    As for now, the print has these "standard" values to have the page centered arround white space which I want to get rid of.
    The webpage itself is shown perfectly when I manually set the marings to 0, but for someone who doens't know how to set these would get the first page printed on the first side, and then the leftover at the start on page 2.
    Is there a way to do this with jsp/html/java? So that the printmargins are sat to 0 at eah "printer friendly" page?
    Please advice - got myself stuck here;) -,
    Cincerely P�l

    Then this might not be a suited javaquestion;) But do you know where to start searching for a solution. I've been googling all over the place for a hint on how to sort this out.
    P�l

  • JSP HTML parameter form to call report - Dependent  drop down list

    I have a report parameter form developed using HTML & JSP to call oracle reports6i.
    First parameter "STATES", Second Parameter "CITY"
    I have a master-detail relation betwen STATE & CITY table.
    I want the parameter form drop down lists dependant. ie if the user chang STATE value in the first drop down, the second drop down list CITY shoud
    change automatically.
    Please help
    Thanks
    Vimal

    Vimal,
    This is not functionality that's available in the Reports generated parameter form. In order to do this you'll need to build the parameter form yourself as a true HTML form and code the javascript to link the fields.
    Hope this helps,
    Danny

  • JSP / HTML page does not load correctly in IE

    I have a particular jsp page, which has heavy volume of data and it does not load completely in IE, but loads perfectly in Firefox and Safari.
    It is a really perpleximg problem that occurs only when the volume of data is large. None of the people in my team were able to solve this issue.
    Please send in your suggestions as to why this is happening or if there are any known bugs in IE.
    In case you need an HTML version of the code, please do mail me at [email protected]

    Jaison_Sabu wrote:
    I have a particular jsp page, which has heavy volume of data and it does not load completely in IE, but loads perfectly in Firefox and Safari.
    It is a really perpleximg problem that occurs only when the volume of data is large. Why would you be sending large amounts of data to a JSP? Sounds fishy to me.
    None of the people in my team were able to solve this issue.Well if you provided your team with the same amount (none) of information you provided here, then I would understand.
    Please send in your suggestions as to why this is happening or if there are any known bugs in IE.Personally, I think it's the flux capacitor.
    In case you need an HTML version of the code, please do mail me at [email protected]
    Hope you're ready for some spam.

  • Dynamic text box generation in jsp page by using net-ui jsp html tags

    Hi All,
    I Need to generate the "TextBoxes" Dynamically by using the "Net-UI HTML Tags".How can i do this ?
    I am using
    1. WebLogic portal server 8.1 sp4 (Workshop dev environment)
    2. JavaPageFlow Applications
    3. Net-UI tags html jsp
    I need to generate the textboxes dynamically and i have to
    get those values in the page flow .
    How it is possible by using the "Net-UI Tags".
    Thanks In Advance,
    KiranBabu.Karusala

    how we create dynemic text box in jsp based one value which we give at runtime

  • How to display data containing CDATA tags in JSP/HTML?

    Hi,
    I'm getting some data from a webservice and displaying it in JSP. But some data from the service (like description of an item) contains CDATA tags.
    For ex: This is the data from the webservice.
    <BenefitsIssues><![CDATA[This strategy buys after a very rapid or extreme sell off with the hope that the gap will eventually be filled. <br>Typically, traders following these types of strategies expect some very large losses as downtrends continue.<br>Traders should take only very small positions when trading this strategy and never dedicate more than a small amount of risk capital in aggregate to this strategy.]]></BenefitsIssues>
    where <BenefitsIssues> is the XML tag. My code displays everything within this tag in JSP.
    Code is JSP looks like this.
    <tr><td><%=strategyDescriptor.getBenefitsIssues()%></td></tr>
    Eventually the HTML output of this JSP looks like..
    <tr><td>![CDATA[This strategy buys after a very rapid or extreme sell off with the hope that the gap will eventually be filled. <br>Typically, traders following these types of strategies expect some very large losses as downtrends continue.<br>Traders should take only very small positions when trading this strategy and never dedicate more than a small amount of risk capital in aggregate to this strategy.]]</td></tr>
    Problem is that the page fails to display the first line, "This strategy buys after a very rapid...." and starts displaying only from "Typically, traders following these....", i.e after the occurrence of first <br> tag. Page also displays "]]" at the end.
    How I can get rid of this problem? One way is to remove "![CDATA[" and "]]" from the data received from webservice. I would like to know if any other better solutions is there. Is there any predefined function to remove "![CDATA[" ?
    Thanks in advance for the help.
    -Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    write tha bean class with the return type like. vector,arraylist .
    add the result set values to vector.
    for example
    Vector s = new Vector();
    while(rs.next)
    s.add(rs.getString());
    at last return that s.
    return s;
    // IN Jsp page;
    <ur dropdown come here>
    <%
    Vector Test = new Vector();
    Test = call function contains databasevalues();
    for(int i=0;i<Test.size();i++)
    %>
    <option><%=Test.get(i)%></option>
    <%}%>
    %>
    Message was edited by:
    kamal_shan

Maybe you are looking for

  • Merging libraries and home sharing

    What is the most efficient way to consolidate and share a library consisting of music from two Apple IDs? Our setup is this: My husband and I each have our own iTunes accounts, plus we have imported our own CDs to our respective libraries. I have a M

  • Missing table extension in Kodo 3.0

    Hi, I liked the class extention key="table" value="..." in the jdo metadata xml files ind Kodo 2.x. Unfortunately I can't find how to specify the tablename in my jdo metadata for Kodo 3.0. I want to generate the mapping with the mapping tool, but it

  • Text file problem

    I wanna search a text file, and get the database name from it. The database name usually follows "BATCH". How can I do that. Thanks.

  • AME 7.2.2 crash

    And here is my issue report. Crashes on launch. Process:     Adobe Media Encoder CC [655] Path:        /Applications/Adobe Media Encoder CC/Adobe Media Encoder CC.app/Contents/MacOS/Adobe Media Encoder CC Identifier:  com.adobe.ame.application Versio

  • All of a sudden I can't log on to I-tunes or the the app store on my I-pad 2

    when clicking on I-tunes or app store my I-pad 2 says it cannot connect and I have good signal it was working I even rebooted it?