Why do we use jsp instead of servlet

why do we use jsp instead of servlet

Hi,
I am and web/Java developer and have used a mixture of JSPs and servlets. I use JSPs for my actual web pages. Whether they are displaying dynamic database driven content or simple pages doing nothing but password protecting.
I tend to separate other reusable code into servlets, like database connections and business logic.
For example: I have worked on a mortgage site and there quite a lot that goes into calculating a monthly payment and ARP. These calculations will not change (only values I send to them will) therefore I do this type of coding in a servlet.
Cheers
Mark
:o)

Similar Messages

  • Why we should use JSP instead of Servlet ?

    I want to know what are the advantages to use JSP over Servlet.

    hi
    Servlets are server exctension ( like CGI ) separate executable
    modules to serve any request efficiently.
    Servlets are pure java classes, u can use them the write an html code to browser.
    u have to compile the servlet before u use it.
    JSP page, is a text-base document , u can type html inside it , and u can use java as scripting language, so it is more easy to use jsp rather than servlet as each jsp page is translated into a servlet by JSP engine.
    Hope this will help
    Good luck
    Mohammed

  • Why do we use jap instead of servlet

    why do we use jap instead of servlet

    JSPs are compiled into servlets. Use them to more conveniently generate presentation code such as HTML. With a JSP, you can code the HTML directly, no need for lots of "out.println" statements. JSPs can be written by non-programmers who don't know Java using the built-in JSP features plus custom tags libraries.

  • I cannot use a website I need to use, with Firefox 5.0. So, I need to uninstall and go back to 3.5 or 3.6. Please advise. Also, my control panel locks up since Windows Explorer has pbms. Which is why I am using Firefox instead. Thanks for any help!

    I cannot use a website I need to use, with Firefox 5.0. So, I need to uninstall and go back to 3.5 or 3.6. Please advise. Also, my control panel locks up since Windows Explorer has pbms. Which is why I am using Firefox instead. Thanks for any help!

    ''I figured it was going to be FAFSA causing your problem.''
    Install Portable Firefox 3.6.x to your hard drive for that one website. It won't affect your current Firefox installation at all. <br />
    http://portableapps.com/apps/internet/firefox_portable/localization#legacy36

  • Why do you use jsp:useBean?

    Hi,
    I have one "simple" question :) : When or why do you are using <jsp:useBean>,<jsp:getProperty> and <jsp:setProperty>?
    For practice, I am creating a form, sends the data to a servlet and the servlet "packs" the parameter into a Bean and put this Bean into a request- or SessionScope. After that, my resultpage could access the property name of the bean with (for instance) sessionScope.Bean.name.
    I wanted to use the 3 tags above first, but after I realised the way I describes above I didn't have to use these three jsp tags. Therefore I wonder when you are using these tags.
    Thnx
    Alex

    hi
    The component model for JSP technology is based on JavaBeans component architecture. JavaBeans components are nothing but Java objects which follow a well-defined design/naming pattern: the bean encapsulates its properties by declaring them private and provides public accessor (getter/setter) methods for reading and modifying their values.
    Before you can access a bean within a JSP page, it is necessary to identify the bean and obtain a reference to it. The <jsp:useBean> tag tries to obtain a reference to an existing instance using the specified id and scope, as the bean may have been previously created and placed into the session or application scope from within a different JSP page. The bean is newly instantiated using the Java class name specified through the class attribute only if a reference was not obtained from the specified scope. Consider the tag:
    sun site

  • Why does people use JSP Tag for their JSP page? (Urgent)

    I don't know what benifit if I am using JSP Tag.
    If anyone knows, pls give me an idea and the advantage of using JSP Tag in JSP Page!
    Thanks in advance!

    You have to read a little about JSP, JSP stands for JavaServer Pages, you can use jsp tags and you can use java code. If you dont want to use jsp tags then you should just write html file, if you just want to use java, then write java class or a servlet.
    The need for jsp arised because people were inserting html code inside a servlet class..a big no no..and a headache. JSP separate model from the view...read a little about MVC-2 model view controller pattern.
    Also read some tutorial on this website...good luck
    K

  • Need Help Badly on Shopping Cart Using JSP And Java Servlet

    Hi All,
    This is the 1st time i am trying to create a shopping cart using JSP and Servlet.
    I have read through a few acticles but i still do not get the whole idea of how it works.
    Please guide me as i need help very badly.
    Thanks.
    This is one of the jsp page which displays the category of products user would like to buy : Products.jsp
    <html>
    <head>
    <title>Purchase Order</title>
    </head>
    <body topmargin="30">
    <table border="0" width="100%" id="table1" cellpadding="2">
         <tr>
              <td bgcolor="#990000" width="96">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">
              Code</font></b></td>
              <td bgcolor="#990000" width="260">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">
              Description </font></b></td>
              <td bgcolor="#990000" width="130">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">Brand
              </font></b></td>
              <td bgcolor="#990000" width="146">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">UOM
              </font></b></td>
              <td bgcolor="#990000" width="57">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">Unit<br>
              Price </font></b></td>
              <td bgcolor="#990000" width="62">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">
              Carton<br>
              Price </font></b></td>
              <td bgcolor="#990000" width="36">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">
              Qty</font></b></td>
              <td bgcolor="#990000" width="65">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">Add<br>
              To Cart</font></b></td>
         </tr>
    <tr>
    <td align="center" width="96" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">123</font>
    </td>
    <td align="center" width="260" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">Tom Yam</font>
    </td>
    <td align="center" width="130" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">Nissin</font>
    </td>
    <td align="center" width="146" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">12 x 10's</font>
    </td>
    <td align="center" width="57" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">$3.85</font>
    </td>
    <td align="center" width="62" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">$46.2</font>
    </td>
    <td align="center" width="36" bgcolor="#CCCCCC">
    <!--webbot bot="Validation" S-Data-Type="Integer" S-Number-Separators="x" -->
    <p align="center"><input type="Integer" name="Q10005" size="1"></p>
    </td>
    <td align="center" width="65" bgcolor="#CCCCCC">
    <p><input type="checkbox" name="checkbox" value="123"></p>
    </tr>
    <tr>
    </table>
    <table border="0" width="100%" id="table2">
         <tr>
              <td>
              <div align="right">          
                   <input type="hidden" name="hAction" value="AddToCart"/> 
              <input type=submit name="submit" value="Add To Cart"/>                     
    </div>
    </td>
         </tr>
    </table>
    </body>
    </html>
    After user has make his selection by entering the qty and ticking on the check box, he would click the "Add To Cart" button ... and this would call my servlet : AddToAddControlSerlvet.java
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    import java.util.*;
    import java.util.ArrayList;
    public class AddToCartControlServlet extends HttpServlet
         public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
              String action = req.getParameter("hAction");
              if (action.equals("AddToCart"))
                   addToCart(req,res);
         public void addToCart(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
              try
                   String url = "";
                   String[] addList = req.getParameterValues("checkbox");
                   HttpSession sess = req.getSession(true);
                   //String sessionID = sess.getId();
                   DBClass dbClass = new DBClass();
                   ArrayList cartList = new ArrayList();
                   for (int i = 0; i < addList.length; i++)
                        String productCode = (String)addList;
                        int qty = Integer.parseInt(req.getParameter("Q"+productCode));
                        Products product = dbClass.getProductDetail(productCode);
                        double totalUnitAmt = qty * product.getUnitPrice();
                        double totalCartonAmt = qty * product.getCartonPrice();
                        Order order = new Order(product.getProductCode(),product.getProductDesc(),product.getBrandName(),product.getUom(),qty,product.getUnitPrice(),product.getCartonPrice(),totalUnitAmt,totalCartonAmt);
                        cartList.add(order);
                   sess.setAttribute("cartList", cartList);
                   url = "/Cart/CartDetails.jsp";
                   ServletContext sc = getServletContext();
                   RequestDispatcher rd = sc.getRequestDispatcher(url);
                   rd.forward(req, res);
              catch (Exception e)
                   System.out.println(e);
    From here, i would get the list of items which user has selected and add to the cartList, then i would direct the user to CartDetails.jsp which displayed the items user has selected.
    From there, user would be able to remove or to continue shopping by selecting other category.
    How i do store all the items user has selected ... everytime he would wan to view his cart ...
    As i would be calling from jsp to servlet .. or jsp to servlet ... and i do not know how i should go about in creating the shopping cart.

    Hi !
    Yon can use a data structure as vector and store the items selected by the user into the vector . Keep the vector in session using session object , so the user can access the entire shopping cart from anywhere in the application .
    Then , you can change the cart accordingly .
    Hope this works.
    Cheers ,
    Pranav

  • Why should I use Publish instead of Routing for SOAP messages over JMS?

    Hi,
    I currently read the book "The Definitive Guide to SOA - Oracle Service Bus" and found the following sentence in the chapter "Wrapping an Asynchronous Web Service with a Proxy Service" on page 131, which confuses me:
    When you send a SOAP message over a JMS queue, you need to use the Publish action, not the Routing action. <<Are there general restrictions, when to use Publish and when to use the Routing action in asynchronous communication? Is this special for SOAP messages over JMS?
    Thanks for your advices,
    Katja

    Here are a few reasons why. Enjoy!!
    A
    What Can Amazon Web Services Be Used For?
    Although Amazon Web Services is a cool technology, it also provides the very useful function of enabling business partners to interact with Web site through standard protocols. This interaction can lead to a deeper, more valuable relationship for parties involved. Here are a few of the ways that partners are benefiting from Web Services:
    Associates: Associates program enables Web sites to link to Amazon.com and earn referral fees for sales that they drive through their links. Many Associates are now using Web Services to build more effective links to our store, thus enhancing their sites and earning more money.
    Sellers and Vendors: Amazon.com has thousands of third-party sellers who offer their products on our Web site. Using Web Services, these sellers can more easily manage large quantities of inventory on our platform, and download the latest product information to make sure that their products are competitively priced.
    Developers: Among the thousands of developers who have signed up to our Web Services program, many are now creating solutions to help other people work with Amazon. These solutions are powered using our Web Services APIs.
    www.amazon.com/gp/aws/landing.html

  • Hi Friends, Please help me to understand Why we are using CHARM instead of

    Hi friends,
    I am working as SAP security consultant.
    I am fresher and worked in implemetaion project.
    My question is when i was in implementation project i used CHARM in sol man to create transport request.
    Now i am working in support and here we are not using CHARM simply creating transport in PFCG.
    So is there any specific difference between both.
    Please tell me

    Hi
    CHARM is a specific functionality in Solution Manager
    so it doesn't mean in all your project or customer are using solution manager charms functionality
    therefore you will creating TR from Se09 etc not from UC/NC scenario
    Hope clarified your doubt
    regards
    Prakhar

  • Why should we use DSO instad of Infocube i BW7.4-SAP BW7.4

    Dear All,
    now I'm working with HCM- Payroll (BWreports) Standard reports, data flow is datasource--->Infocube--->Reports, but my architecture given data flow datasource--->DSO--->Multiprovider-->Reports, this is in SAP BW7.4, could any one explain me why should we use DSO instead of infocube..
    Thanks for your helping...
    Regards,
    Narasimha

    Hi
    In Loading purpose:
    Better to use DSO, becouse it involves 3 tables ie New data table, Active data table and Change log table.
    in case of INFO CUBE, here it involves more than 3  tables ie by default 3 dimension tables are existedby SAP... at least we will create 2 tables ie 1 dimension table and 1 fact table ....here it involves 5 tables.( 3 default+1 dimension+1 Fact table)
    Conclusion: When we create INFO CUBE it will takes more time compared to DSO because it involves 3 table
    Conclusion: Best practice is when we load data to taget, better to use DSO
    In Reporting:
    Cube will give summerised data whyle reporting and it is multi dimensional,ie we can analyse the data in multiple ways.
    DSO will give detailed data whyle reporting and it is 2 dimensional , ie we can analyse the data in 2 dimensional way only
    Conclusion: Best practise is Whyle reporting better to use INFO CUBE
    Regards
    Raj

  • Why should I use SQLJ

    Why should I use SQLJ instead of JDBC, is it for faster Acess than JDBC, or for any other reasons

    Why should I use SQLJ instead of JDBC, is it for
    faster Acess than JDBC, or for any other reasonsJust guessing...
    It should be faster - but you should test.
    I would suspect that it is going to be harder to maintain because it is less used (thus less tested), less known (so harder to hire people to maintain) and less 'standard' (thus figuring out what went wrong can be harder.)

  • Why we are using servlet as a controller instead of Jsp?

    Can any explain answer for this question
    Thanks in Advance
    Why we are using servlet as a controller instead of Jsp?

    nareshannam wrote:
    Can any explain answer for this question
    Thanks in Advance
    Why we are using servlet as a controller instead of Jsp?Basically JSPs are suited to do just one thing, to generate HTML with variable content. You can put Java code in there too, but it's not a good place for it. Messy to validate, messy to debug. In fact, with tag libraries like JSTL, actual Java code is rare in professionally written JSPs.
    A controller does the bit that comes before you've decided what kind of response the user is going to get, typically it may invoke one of several JSPs according to validation etc.. There's a lot of logic, a lot of parsing parameters and so on. Much cleaner to do this from a Java class like a Servlet.
    Judging by this forum quite a lot of people come to JSPs from ASP or PHP and don't want to bother with actually writing Java classes. That's never going to be much good.

  • Why do we use both servlets & jsps in developing  an application ?

    why do we use both servlets & jsps in developing an application & not only jsps

    Hi,
    It's a pure question of design : Some like it jsp to jsp and others servlet to jsp. It's up to you to decide and it depends of the complexity of your application.
    But the best design is the MVC (servlet and jsp working together) because it helps you separate presentation from logic. It also helps you better maintain you code.
    You can have more info in javaworld.com.
    Good luck
    touco

  • Why do we use init() method instead of constructor to initialize a servlet?

    Why do we use init() method instead of constructor to initialize a servlet?

    I suspect the reasons are partly historical. A servlet is loaded dynamically, by class name and, once you've loaded the Class, it's easier to to a newInstance, using the default construtor than it is to search for a particular matching constructor and invoke it.

  • Facelet to crare web app, instead of using JSP; JSF1.2 spec in WebSphere6.1

    Novice to JSF and Facelet. But, I had been using Struts since its inception.
    I am required to use IBM's WebSphere Application Server 6.1 that comes with Servlet 2.4 and JSP 2.0. WebSphere 6.1 App Server limits me to using JSF 1.1. This is because, JSF 1.2 requires Servlet 2.5 and JSP 2.1, that is a part of WebSphere App Server 7.0; not a part of WebSphere 6.1.
    Somebody suggested that it will be possible to use JSF 1.2 in WebSphere 6.1, if I were using Facelet, instead of JSP.
    I am not eager to use JSF 1.1 and may have to forego JSF; unless and until I can use JSF 1.2.
    The hold-up is that I cannot use JSF 1.2 spec in WebSphere 6.1. Is there is any way to use JSF 1.2 in WebSphere 6.1? Can I create an entire application using Facelet (instead of JSP) that will let me use JSF 1.2 spec in WebSphere 6.1? If so, how?
    Here are my questions, especially because I am not very familiar with JSF and Facelet technology:
    1. Can I use JSF 1.2 specification in WebSphere 6.1, if I were using facelet (as opposed to JSP) as my view technology?
    2. Will it be possible to create an entire web app with facelt, instead o fusing any JSP at all? If so, how? Does it mean that all the GUI screens will only use facelet and no JSP at all?
    3. Please explain how I can write a complex web app with 100s of screens using only facelet, instead of using JSP.
    4. Please provide pointer on how JSF and facelet differ, or what are their demarcations boundaries.
    Any comment and pointer will be greatly appreciated.

    Don't doublepost. It's rude. Stick to one topic. Continue here: [http://forums.sun.com/thread.jspa?threadID=5335001].

Maybe you are looking for

  • Why does some artwork embed into the file, but not others?

    Hey everyone. I'm running iTunes 11.3.1. I'm incredibly obsessive about having organised files and one thing in particular I want is album artwork embedded into the music file itself, not just on iTunes. The problem I have is that the artwork will em

  • Can't receive mail, Relay access denied

    Hello all, I am new to Ma c OS Server, so i apologize if this topic has already been covered before. However, I have spent several hours browsing through different discussions and still couldn't figure out where my problem is. I have set up a new Mac

  • IQ526t hard disk crash

    Hi everyone, I am in a serious situation. I have this HP Touchsmart IQ526t that I bought in year 2009, recently the hard disk found faulty by hardware diagnostic tool. I ave replace a new 2G hard disk with 7200rpm. When I tried to install recovery di

  • Need to disable E2500 Ports on router.

    Hello, i have an E2500 and i need to disable the ports on the router. I have a DSL line going in and thats it. I do not want it to be able to accept any wired device and have someone get on the internet. I do not want someone to just take a laptop, w

  • How can i use Bi-Technical Content is used for measuring the performance of

    Hi recenetly i implemented the BI7.0 for one client. I want to know how to use 'BI Administraction Cockpit,. Actual what technical content does ??? And how can i use technical content or statistics for measuring the performance of my queries. Please