Multiple servlets vs parameterized service

I'd appreciate any advice/reccomendations anyone has on this topic
What are the trade offs in the following scenario where I have a set of related use cases I want my web app to handle. Is it best to have a servlet per use case (eg in a web store, I might have "buy item", "list products", "view cart") or is it best to have a single servlet and have that distinguish the particular use case from the URL/input parameters.
What are the overheads of multiple servlet objects in this scenario esp where as in the exampe above a "buy item" would affect the results of "view cart"
I realise I can use struts or similar to achieve the described effect, I'm more interested in the technical factors behind the choice above
thanks

its better if u can have only 1 servlet for alll the use case.it can be your Controller and this is called MVC arch. If u use seperate servlet for each use case then u have to repeat generic code in each servlet and u also be writing the business in the servlet thats worng. u should write all the business in seperate class which may be reused and this is called model in MVC.if u use single servlet it may become long but u can seperate in 2 or more but not each servlet for each use case.

Similar Messages

  • Problem with running multiple servlet in same webapplication with tomcat 3

    Hi all,
    I am using Tomcat 3.0 as webserver with jdk1.3, Servlet 2.0,
    Templates for html file and oracle 8i on UNIX platform.
    I have problem with multiple servlet running same webapplication.
    There are two servlet used in my application. 1) GenServlet.class
                   and 2) ServletForPrinting.class
    All of my pages go through GenServlet.class which reads some property files
    and add header and footer in all pages.
    I want reports without header & footer that is not possible through GenServlet in my application.
    So I have used another servlet called ServletForPrinting --- just for reading html file.
    It is as follow:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ServletForPrinting extends HttpServlet {
    public void service (HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException
    // set content-type header before accessing the Writer
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    File f1 = null;
    String report = null;
    String path = request.getPathInfo();
    try{
    String p = "/var/home/latif/proj/webapps/WEB-INF/classes" + path;
    System.out.println(p);
    f1 = new File(p);
    p = null;
    if (f1.exists()) {
    FileReader fr = new FileReader(f1);
    BufferedReader br = new BufferedReader(fr);
    report = new String();
    while ((report = br.readLine()) != null) {
    out.println(report);
    }catch(Exception e) {
    out.close();
    report = null;
    path = null;
    f1 = null;
    } // end class
    It works fine and display report properly.
    But now Problem is that if report is refreshed many times subsequently,
    WebServer will not take any new change in any of java file used in web-application.
    It works with the previous class only and not with updated one.
    Then I need to touch it. As soon as I touch it, webserver will take updated class file.
    Anybody has any idea regarding these situation?
    Is there any bug in my ServletForPrinting.java ?
    Any solution ????? Please suggest me.
    Suggestion from all are invited. That will help me a lot.
    Thanks in advance
    Deepalee.

    Llisas wrote:
    I solved the problem, I just had to wire the blocks in a sequential way (I still don't know why, but it works).
    Feel free to delete this topic.
    I would strongly suggest at least reading this tutorial to give you an idea of why your fix worked (or maybe only appeared to work).  Myself, I never just throw up my hands and say, "Whatever," and wash my hands of the situation without trying my best to understand just what fixed it.  Guranteed you'll run into the same/similar problem and this time your fix won't work.
    Please do yourself a favor and try to understand why it is working now, and save yourself (or more likely, the next poor dev to work on this project) some heartache.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • Adding multiple servlets under same application

    Hi,
    We are trying to add multiple servlets (2 to be precise) to an Application.
    We are using j2ee1.3 server and deploytool for deploying the same.
    Is it possible to have a single context root in which i'll be able to place both servlets with different aliases to access them?
    The moment I specify same contextRoot in Web context tab of Application, i get an error saying Deployment failed because "mycontextroot" already exists.
    When I assign two different context roots to each servlet, they can function, but then the URL for each changes inspite of being in the same application.
    Any suggestions are welcomed.
    Thank you,
    Manish.

    Hi,
    I did not quite follow the solution and I am wondering if it will solve a problem I am having.
    I wish to define multple jax-rpc endpoints, but I want the classes servicing those endpoints to be able to communicate with one another. I tried placing them both in the same war and entering two endpoints in the jaxrpc-ri.xml file, but it didn't like the second endpoint entry being there.
    Is there a way to do this?

  • Sharing config with Servlet and Web Services

    Hi,
    I am building a Servlet wrapper and a jaxrpc wrapper for my application, so that my client can invoke either servlet or web services to access my application.
    my main application library is at WEB-INF/lib and both the servlet and
    webservices are in WEB-INF/classes.
    I am trying to make them sharing the same configuration file web.xml so that common attributes such as log file location can be read. I know Servlet can read the context and parameters but how to make my web services app to read it, since the web services are not servlet itself but it is invoked by the JAXRPC servlet????
    Thanks

    The early post may answer your question:
    http://forum.java.sun.com/thread.jsp?forum=331&thread=266102

  • How to use my connection pool in multiple servlets?

    I now have a functioning connection pool using these lines in a servlet:
    private Connection getConnection(String lookup) throws NamingException, SQLException {
    Context context = new InitialContext();
    DataSource ds = (DataSource)context.lookup(lookup);
    Connection ocon = ds.getConnection();
    context.close();
    return ocon;
    } // private Connection getConnection(String lookup) throws NamingException, SQLException {
    ========================
    If I want to create additional servlets in the same web app which query the same database,
    do I need to repeat this block of code in every servlet, or can I just put it in one servlet
    and have other servlets access it in some way to get a connection? Should I change the code
    above from a "private" Connection to a "public" Connection?
    An example servlet is shown below. To put my question another way: If I want to
    create a second servlet with a different set of queries, would I just make a copy of the first
    servlet and then change only the queries, or is there a more efficient way to have multiple
    servlets get connections from the pool?
    Any suggestions are greatly appreciated.
    Thank you.
    Logan
    ************************************servlet example**********************************
    package CraigsClasses;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import java.net.*;
    import java.util.*;
    import java.io.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.util.Date;
    import java.text.*;
    import javax.naming.*;
    import javax.sql.DataSource;
    public class CraigsMain extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    private Connection getConnection(String lookup) throws NamingException, SQLException {
    Context context = new InitialContext();
    DataSource ds = (DataSource)context.lookup(lookup);
    Connection ocon = ds.getConnection();
    context.close();
    return ocon;
    } // private Connection getConnection(String lookup) throws NamingException, SQLException {
    // Process the http Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
    try {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String sql = "select formtitle from checkboxforms where cbformid = 157";
    // error occurs at this line
    Connection ocon = getConnection("java:comp/env/jdbc/CraigsList");
    PreparedStatement pStmt = ocon.prepareStatement(sql);
    ResultSet rs1 = pStmt.executeQuery();
    rs1.next();
    out.println("<br>" + rs1.getString(1));
    rs1.close();
    pStmt.close();
    ocon.close();
    } catch(SQLException sqle) {
    System.err.println("sql exception error: " + sqle);
    } catch(NamingException ne) {
    System.err.println("naming exception error: " + ne);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    =======================================================================

    sjasja, Thank you for the reply. What you are suggesting is exactly what I have been looking for. But I'm pretty weak on how to make this separate con pool servlet work. My first attempt is shown below. It doesn't compile this line, which is obviously wrong:
    public static Connection getConnection(String lookup) throws NamingException, SQLException {
    Could you please help me with this servlet code? Thanks.
    package CraigsClasses;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import java.net.*;
    import java.io.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import javax.naming.*;
    import javax.sql.DataSource;
    public class ConPoolInit extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {
    public static Connection getConnection(String lookup) throws NamingException, SQLException {
    Context context = new InitialContext();
    DataSource ds = (DataSource)context.lookup(lookup);
    Connection ocon = ds.getConnection();
    context.close();
    return ocon;
    } // private Connection getConnection(String lookup) throws NamingException, SQLException {
    } catch(SQLException sqle) {
    System.err.println("sql exception error: " + sqle);
    } catch(NamingException ne) {
    System.err.println("naming exception error: " + ne);
    =======================================

  • EDI invoice failed for Service- multiple tax code at service item level

    Hi Guys,
    Please understand below scenarios, it is very critical to our client.
    purchase order has 3 parent
    line item which having the 3 services with tax code (P1-P1-P1 and P2-P2-P2 and (P2-P1-C1)
    (P1=10%, P2=10% and C1=10%)
    PO Outbound Idoc -
    Similar tax codes(P1-P1-p1 and P2-P2-P2) - Carries total tax amount and
    tax rate at parent level also it carries indvidual service line item
    tax amount and tax rate at service item level
    Mulitple tax codes(P2-P1-C1)- Carries only total tax amount at parent
    level and no tax rate at parent level. It carries indvidual service
    line item tax amount and tax rate at service item level
    SES Outbound Idoc -
    Similar tax codes(P1-P1-p1 and P2-P2-P2) - Carries total tax amount at
    parent level segment and tax rate at parent item level also it carries
    indvidual service line item tax amount and tax rate at service item
    level
    Mulitple tax codes(P2-P1-C1)- Carries only total tax amount at parent
    level and no tax rate at parent level. It carries indvidual service
    line item tax amount and tax rate at service item level
    But while creating the invoice for parent line item which includes 3
    services, it carries correct tax amount(as per PO and SESR) but it is
    asking for tax rate at parent level not at service item level.
    It is working fine for similar tax code at service line item (e.g P1-P1-p1 for 3 services or P2-P2-P2 for all 3 services) but when we use the combination of tax code or multiple tax code at service line items (e.g. P2-P1-C1), the inbound Idoc gets failed.
    Expectation - How EDI invoice posted for mulitple Services under one parent line item which having multiple tax codes at service item level
    Thanks
    Sanjay
    9930851236

    This is an ongoing problem with lots of clients - did anyone solve it ?

  • How to expose custom methods of servlet as web services

    Can i know how to expose the custom methods of the servlet as web services. if it is not posssible then what alternate ways are possible other than ejbs?
    regards

    Hi
    I want to know that whether the custom methods of servlet can be exposed as webservices or not?
    Secondly is there init method like we have in servlets so that we can do all the one time loading in the init() method.
    regards

  • Using Show parameters service

    good morning,
    Dont know if this is the right thread for this question but here it goes:
    I was using Show Parameters Services 2 days ago to aquire a list of all current service names and it was returning info just fine.
    I then proceeded to add 1 more 'serviceName' to the list and then ran an alter command to updae that list. It all worked.
    But when i tried to reuse the Parameter services command again, it return an empty string. I did check in the appropriate table and the extra record is available with the other previouslly viewed service names.
    Is there some sort of limitation on Show parameters service that i dont know about? (On the return of info).
    I hope this makes sence.
    Can i get confirmation of what might be happening and if i can do anything to rectify this from cntinuing to happen.
    Thank you very much...

    Is this to do with using the SQL*Plus [SHOW PARAMETERS|http://download.oracle.com/docs/cd/B28359_01/server.111/b31189/ch12041.htm#sthref2262] command to list the current [SERVICE_NAMES|http://download.oracle.com/docs/cd/B28359_01/server.111/b28320/initparams217.htm] setting?

  • Upon computer startup: "Atte​mpted to start multiple instances of the service&qu​ot;

    Recently installed Diadem and there must be some sort of registry error.  Whenever I startup I get the error "Attempted to start multiple instances of the service" anyone know the registry fix for this? Thanks!
    Attachments:
    NI startup error.jpg ‏16 KB

    Hey Kyle,
    Check your services and see what’s running.  This can be done by going to Start>>Run and type “services.msc”.   Then look for anything that starts with National Instruments or NI.  Look to see if there are any entries running twice or if you are trying to call a service that is already running.
    Nick
    National Instruments
    Applications Engineer

  • JDeveloper starting multiple servlets

    Two questions.
    1. Is there anyway to start/debug and alias multiple servlets.
    2. Can JDeveloper's "webtogo" engine be replaced with something else such as LWS.
    My goal is an environment where I can start/debug and alias multiple
    servlets all from JDeveloper's IDE.
    Any help would be appreciated.
    Thanks
    null

    Yes, you could start multiple servlets in JDeveloper IDE.
    check online help
    Open help system
    Select the topic "Developing Java Servlets"
    select "registering a servlet with web object manager"
    You could register multiple servlets and run one of the servlets from the IDE and later on
    change the servlet name in the URL to run the other servlet.
    raghu

  • EIT Multiple Rows in Self Service using Personalization

    The EIT is set up in core HRMS as multiple rows descriptive flexfield having segments each with value set and default values.
    Multiple rows meaning, user can enter multiple records as extra information as compared to DFF which only allow one record..
    The requirement is to attach this EIT in iRecruitment (self service, HTML) using personalization.
    My Question ?
    1. Can I add this EIT as flex item ?
    2. do I have to create EO, VO and AM for this EIT table or this is provided by oracle when EIT is created ?
    3. is the EIT displayed as table in page with add, update delete button.
    4. is there any document which describes steps to add EIT with multiple rows to self service apps.
    Help Appreciated
    Thanks

    I am still facing issue in displaying the restricted record in self service.
    Setup tried:
    1. My original value set has the total set of values (no validation).
    2. My new value set is a wrapper over the original and uses a Table validation with a WHERE condition like:
    WHERE flex_value_set_id = <original value set id>
    AND
    (FND_PROFILE.VALUE('RESP_ID') = <MSS resp id> and flex_value
    <> "<restricted values>")
    or
    (FND_PROFILE.VALUE('RESP_ID')= <PUI> and 1=1)
    Result:
    SS lov shows only filtered values, I cannot select it in new record.
    But I get error when the already created record gets displayed as it seems to validate against new value set.
    error:
    ID <restricted value> for the flexfield segment SEGMENT1 does not exist in the value set NEW VALUE SET.
    Is there any possibility to add a table filter in MSS to restrict the record that is displayed in the EIT table in SS. I tried a lot but the filter do not bring the table columns for adding the filter clause.
    Or is there a way that I can attach different value set for PUI through Forms Personalization?
    Thanks for your suggestions.

  • Update query with multiple foreign key parameters

    I am trying to perform an update query on one field that uses multiple foreign key parameters from one table to update the other table. The data in all three foreign key parameter fields are not constant. Accuracy is absolutely critical. I tied this as well as other various scenarios with no success. Can anyone help?
    Update A_table a
    set a.rate = (
    select b.rate
    from B_table b
    where b.id = a.id
    and b.transdate = a.transdate
    and b.orgnum = a.orgnum
    and b.transdate = to_date('31/12/2007', 'dd/mm/yyyy')
    )

    I would check symbols by a user name and number of posts before calling anyone a hot shot, especially damorgon.<br><br>
    Yes version matters (due to bugs and features in each version).<br>
    DDL matters because of indexes and associations.<br>
    Data matters because it makes a difference on how SQL can be written.<br>
    Reasons why an SQL statement don't work is because we aren't looking over your shoulder at your screen.<br><br>
    damorgon did leave off his list that the best place for this question is on the PL/SQL, where they will ask you similar questions in addition to your explain plan and data volumes.

  • Servlet Calling Web Service

    Hi
    I need to call a web service via a servlet
    Both web service and servlet files are located on the same PC , but in a different directories
    the web service is working OK when I use a command line,
    However , when I try to use a Servlet method to activate the web service and retrieve some information public void doPost (HttpServletRequest request,HttpServletResponse response)  throws   ServletException ,IOException{
    serve.businessVector = (Vector)uddiClient.getuddiInformation("dublin");
    The service Client is the activated ok and when the programm reaches a particular point in the code    Service service = new Service(); I receive an error as follows
    java.lang.NoClassDefFoundError
         at org.apache.axis.client.Service.getAxisClient(Service.java:143)
         at org.apache.axis.client.Service.<init>(Service.java:152)
    Could someone please direct me on what is going on
    Or am I using the wrong approach ?
    and here is the method I am using for the service client
    public Vector getuddiInformation(String location )throws Exception {
    String endpoint = "http://localhost:8080/axis/UDDIRegistry.jws"; // here where the jwsfile is located
    // set the end point ie the URL for the call
    Service service = new Service();               
    Call call = (Call) service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(endpoint));
    call.setOperationName("readXML");
    // now invoke the method in the registry
    // ie  int the UDDIRegistry.jws
    Vector ret = (Vector) call.invoke(new Object[] {new String(location)});
    uddClientVector = ret ;
    return  uddClientVector;
    }Thanks
    IB

    java.lang.NoClassDefFoundErrorYour classpath is apparently incorrect, to put it
    simply. When you "run it from the command line" you
    are running it differently, with a different
    classpath than you are when this is encountered. This
    being a J2EE app, your WAR or EAR file (or
    directory-exploded equivalent) needs to contain all
    the dependent classes/jars, and apparently you
    haven't created that correctly.I have checked the classpath and it seems to be ok
    The jar file ( axis.jar ) that I think is causing the error is included in the AXISCLASSPATH and in the CLASSPATH
    OS is Win XP
    the following errors remain -->
    java.lang.NoClassDefFoundError
         at org.apache.axis.client.Service.getAxisClient(Service.java:143)
         at org.apache.axis.client.Service.<init>(Service.java:152)
         at TempServelet.start1(TempServelet.java:72)
         at PostHTMLResult.fillArray(PostHTMLResult.java:65)
         at PostHTMLResult.doPost(PostHTMLResult.java:83)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
    and 25 more errors
    I have checked the documnts for Tomcat 4.1 and axis for the setting the classpath , I dont know If there is a special setting I need to do ??
    Please advise
    Thanks
    IB

  • Invoking multiple servlets from a single request

    Hi. I'm wondering if it's possible to execute multiple servlets within a single request and context. I have a servlet defined in web.xml which says:
    <servlet>
    <servlet-name>firstServlet</servlet-name>
    <servlet-class>mypackage.First</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>firstServlet</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>
    (clearly this one gets invoked upon every request in the context)
    But I also have another servlet which gets invoked when another condition applies:
    <servlet>
    <servlet-name>secondServlet</servlet-name>
    <servlet-class>mypackage.Second</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>secondServlet</servlet-name>
    <url-pattern>*.ftl</url-pattern>
    </servlet-mapping>
    So if the url was http://localhost:8080/mycontext/page.ftl, I want both servlets to get executed. Is there anyway I can do this? I've tried the above code and it doesn't work. How would I do this (or can I even do it)?
    Thanks,
    Dylan

    depending on what your servlets do, you might also think of using filters. say you have a first servlet that compresses the respone you would be better off to implement this as a filter. than you might have a second serlvet that does request logging stuff. this might also be better than in a filter, so you chain first and second filter. the business logic is put in servlet three i.e.

  • Can't define init parameters for multiple servlets

    I want to define init parameters for two servlets in the web.xml file but i only get null for my Login servlet
    <web-app>
    <servlet>
    <servlet-name>
    RSServlet
    </servlet-name>
    <servlet-class>
    RoadSafe.Servlet.RSServlet
    </servlet-class>
    <init-param>
    <param-name>serverip</param-name>
    <param-value>localhost</param-value>
    </init-param>
         <load-on-startup>
              2
         </load-on-startup>
    </servlet>
         <servlet>
    <servlet-name>
    Login
    </servlet-name>
    <servlet-class>
    RoadSafe.AdMisc.Login
    </servlet-class>
    <init-param>
    <param-name>serverip2</param-name>
    <param-value>localhost</param-value>
    </init-param>
         <load-on-startup>
              1
         </load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>
    RSServlet
    </servlet-name>
    <url-pattern>
    /RSServlet
    </url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>
    Login
    </servlet-name>
    <url-pattern>
    /Login
    </url-pattern>
    </servlet-mapping>
    </web-app>

    In the code for you Login servlet, are you using the name "serverip2" to access the initial parameter ?
    Thats the name you have used in the web.xml file.

Maybe you are looking for

  • Built-In Audio Panning L&R malfunctions, system prefs.

    I have noticed on my own Mac, as well as my peers' computers which include iBooks, PowerMacs, iMacs, and even a new MacBook pro, that the audio coming from the Built-in audio card will randomly be panned completely to the right, or the left. A quick

  • Issues with Hard Drive & Disk Repair

    I keep getting the following when I try to verify my hard drive with the Disk Utility: Volume Header needs minor repair The volume Macintosh HD needs to be repaired. Error: The underlying task reported failure on exit 1 HFS volume checked Volume need

  • New Intel driver brings substantial performance improvements.

    Has anyone else noticed that the new X.org Intel driver (2.16.0) is significantly better than what preceded? Before this most recent upgrade, I couldn't even turn on 3D Compiz effects without the framerate being compromised (unless I disabled Sync to

  • I can't delete the email on my iCloud advanced setting

    Help I can't get rid of the advanced email in my iCloud account on my iPhone 5s, my mail keeps appearing on my daughters iPhone 4. How do I delete it? It's becoming very frustrating... Please could someone help me? Thank You

  • How to do business development?

    Hi, If you've been following my other threads you know that I'm trying to either A) find a new job in Southern California or B) get transferred to the Irvine office of my current company. I want to propose that if they transfer me and if I can't stay