Basis in servlet technology

hey any one out there plz let me wat happens interenally when the container reads the following information provided as part of web.xml,as i am a beginner i am not able to under wat goes on internally.So plz help me in this regard. Let us suppose sone as my servlet name and Srvone as my servlet class and /one be the url pattern for my servlet.
<web-app>
<servlet>
<servlet-name>sone</servlet-name>
<servlet-class>Srvone</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sone</servlet-name>
<url-pattern>/one</url-pattern>
</servlet-mapping>
</web-app>

Here's what happens in your web.xml:
1.) You tell the server that there is a servlet whose name is sone. This is a name you choose to identify the servlet.
2.) Then you tell the server that the servlet you just named is actually contained in the class Srvone. This is the fully qualified class name of the where the servlet code is.
3.) To be able to access the servlet, you need to provide a mapping. So then you go on and tell the server that, you want the servlet whose name is sone to be executed when a request is made to /one.
These three steps have to be taken for your servlet to be accessible.
Clear?

Similar Messages

  • Implementation of application scope in servlet technology

    hello,
    i want to define certain variable with application scope , in servlet technology how to do that

    Attributes can be stored in the ServletContext in the same manner as they are stored in the session.
    String x = "Stored Value";
    getServletContext().setAttribute("x", x);
    String y = (String) getServletContext().getAttribute("x");

  • How to implement use bean tag in servlet technology

    hello,
    i want to use application scope for variables in application . i know about use bean tag but i want to use servelet technology. how could this be done

    The application scope corresponds to the servlet context. From your servlet, use getServletContext().getAttribute() and getServletContext().setAttribute().

  • New to Servlet Technology

    Hi,
    i am new to servlets. Can anyone tell me how can i compile and run a java servlet. ie what do i need i mean application servers and webservers.
    Thanks in advance
    byee

    hi anansmithi,
    Thanks for the reply
    i have installed Tomcat 5.5.4 on my system and its working fine. i have written a small servlet program
    can you tell me how how can i compile and run a servet using tomcat 5.5.4
    thanks in advance
    byeee

  • Problems with the tutorial Introduction to Java Servlet technology

    Has anyone done this tutorial?
    https://www6.software.ibm.com/developerworks/education/j-intserv/
    I created an application. Created the XML file. Imported the project from the website and tried viewing it in the broswer:
    http://localhost:8080/contacts/
    I get this:
    HTTP Status 404 - /contacts/
    type Status report
    message /contacts/
    description The requested resource (/contacts/) is not available.
    Apache Tomcat/5.0.28

    that means you didn't deploy the app properly.
    go read the tomcat docs for "your first web app"
    %

  • Running Servlet in J2EE server

    hello friends
    i am very new to servlet technology, i create the servlet java file and complied it and using j2ee application server (1.4) i deploy it and put the war file at autodeploy file but i cant run it ,how i can use j2ee server for running the servlet, and i also used apache-tomcat-5.5.12 but i cant see any class folder at ROOT/webinf please help me

    I m not familiar with the j2ee server...
    But a bit with Tomcat...
    The tomcat 5.5.X is bit hard to configure..
    I hope you have successfully configured the Tomcat in your PC..
    in that you have to create a directory in
    <your tomcat base directory>/webapps/<yourdirectory>
    in that <yourdirectory>/, you have to create a new folder WEB-INF into which your class file has to go..
    your web.xml file should be placed in <yourdirectory>/
    Doing this is a bit hard to understand..
    I recommend you to use the latest version of NetBeans IDE ..
    it will come with a bundeled Tomcat...you can simply run your servlet files and deploy them very easily with it..

  • Confused what exactly Java Servlets are?

    Hi,
    I(JSP Biginner) have gone through some tutorials about JSP, Servlet and Java bean.
    I'm really confused by the term SERVLET.
    There are a lot of the definitions:
    1.) Is a Java Class that provides special Server Side Specification.
    2.) A servlet is a dynamically loaded module that services requests from a Web server.
    From above mentioned definition, my understanding is, SerVlet is like an engine which is provided server service. Is the SERVLET that I mentioned same as the JSP Servlet Engine which parse the JSP file, generate and compile the servlet source code and then send it to the browser?????
    3.)What about the SERVLET that created by developer and use in the JSP page? what are the differents between the servlet 1,2 and 3.
    Please advice!

    thanks so much...
    guess I have better understand of what java servlet is when I read the article from
    http://www.novocode.com/doc/servlet-essentials/
    from my understanding:
    1.) we said that SerVlet Provides Request and Response services is because the purpose of we creating our servlet is used to Read (Request) the data from Client and Send back (Response) the data to the Client. Of course all this can be done by code in the JSP page, but because of SerVlet technology, instead of we write the long code in the JSP page, we can modularise our code by creating servlet, why?? as servlets are web components, they can be reused easily. Moreover, java servlet is platform independent. After that at our JSP page, we just call the servlet we have created.
    2.)As we can see from all the example, a SerVlet sure has
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    Are all of them only available when we installed our Web Server (i.e tomcat)???
    3.)Can I say that we create servlets by Inherit all the routines and structure in those classes (q.2), as well as use their Built-In functions to create our servlets???
    4.) Can I say that we create servlet by create an instance of a BIG SERVLET which served as a base (Which has all the classes we needes for creating our own servlets)
    I don't know how much you can understand what I'm writting. Anyway, hope u can help.
    Thanks so much.

  • Working Sample Code: File Download Servlet

    Pardon the cross-posting (Java Servlet Technology), but when I was researching this problem I found alot of people asking this question in here as well as in the servlet forum. So I thought this code would be helpful here too.
    Here is a complete working servlet for downloading virtually any type of file to a browser.
    It uses a file called application.properties to specify the location of the folder where the files to be downloaded reside. Of course you could modify this to allow the users to select the location as well.
    A sample URL to call the Servlet would look like this:
    http://localhost/website/servlet/DownloadAssistant?YourFileName.ext
    I tested this with varying filenames. It did have some issues if the file contained special characters like # symbol. This should be manageable however.
    Hope someone finds this useful.
    import java.io.*;
    import java.util.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.zip.GZIPOutputStream;
    public class DownloadAssistant extends HttpServlet
    private static final String DIR = "dir";
    private String separator;
    private String root;
    public DownloadAssistant()
    Properties propFile = null;
    FileInputStream in = null;
    String JAVA_HOME = "C:\\jrun\\servers\\default\\filetest\\application.properties";
    // Get a handle on the peoperties file
    try{
    in = new FileInputStream(JAVA_HOME);
    propFile = new Properties();
    propFile.load(in);
    catch (IOException ignore){}
    separator = "/";
    // Get the directory from the application.properties file
    // e.g. C:\\Temp\\Files\\
    root = propFile.getProperty("app.directory");
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    processRequest(request, response);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    processRequest(request, response);
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    PrintWriter out = null;
    ServletOutputStream stream = null;
    GZIPOutputStream zipstream = null;
    Object obj = null;
    String s = "";
    //determine if there is a filename appended to the url
    // If so, then decode it
    s = HttpUtils.getRequestURL(request).toString();
    int i;
    if((i = s.indexOf("?")) > 0)
    s = s.substring(0, i);
    String s1;
    if((s1 = request.getQueryString()) == null)
    s1 = "";
    else
    //s1 = decode(s1);
    s1 = URLDecoder.decode(s1);
    // No filename, so set contentType and generate error message
    if(s1.length() == 0)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<p>Could not get file name ");
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Restriction while gaining access to the file
    if(s1.indexOf(".." + separator) > 0)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<br><br><br>Restrictions on filename");
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Try to get a handle on the file
    File file = new File(root + s1);
    // Couldn't get the file, return an error message
    if(file == null)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<p>Could not read file: " + s1);
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Either the file doesn't exist or it can't be read, return an error message
    if(!file.exists() || !file.canRead())
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html><font face=\"Arial\" size=\"+1\">");
    out.println("<p>Could not read file " + s1);
    out.print("<br>Reasons are: ");
    if(!file.exists())
    out.println("file does not exist");
    else
    out.println("file is not readable at this moment");
    out.println("</font></html>");
    out.flush();
    out.close();
    return;
    // Looks like we can read/access the file, determine its type
    String s2 = request.getHeader("Accept-Encoding");
    // Is this a zip file?
    boolean flag = false;
    if(s2 != null && s2.indexOf("gzip") >= 0)
    flag = true;
    flag = false;
    if(flag)
    response.setHeader("Content-Encoding", "gzip");
    response.setHeader("Content-disposition", "attachment;filename=" + s1);
    stream = response.getOutputStream();
    zipstream = new GZIPOutputStream(stream);
    downloadFile(root + s1, zipstream);
    zipstream.close();
    stream.close();
    // It's not a zip file so treat it as any other file
    else
    response.setContentType("application/force-download");
    response.setHeader("Content-disposition", "attachment;filename=" + s1);
    stream = response.getOutputStream();
    downloadFile(root + s1, stream);
    stream.flush();
    stream.close();
    }// end processRequest()
    // This method downloads the file to the browser
    private void downloadFile(String s, OutputStream outstream)
    String s1 = s;
    byte abyte0[] = new byte[4096];
    try
    BufferedInputStream instream = new BufferedInputStream(new FileInputStream(s1));
    int i;
    while((i = instream.read(abyte0, 0, 4096)) != -1)
    outstream.write(abyte0, 0, i);
    instream.close();
    catch(Exception _ex) { }
    }//end downloadFile()
    public void init(ServletConfig servletconfig)
    throws ServletException
    super.init(servletconfig);
    String s;
    if((s = getInitParameter("dir")) == null)
    s = root;
    separator = System.getProperty("file.separator");
    if(!s.endsWith(separator))
    s = s + separator;
    root = s;
    }//end init()
    }//end servlet()

    Yes - it is useful

  • How to configure applet/servlet in Tomcat?

    I'm building a web application which is going to be deployed in Tomcat. I have an applet(called MYAPPLET here) which "calls" a servlet(called MYSERVLET here). I cannot figure out how to configure the whole thing.
    /test is my docbase. In /test I made a directory "applet classes" and a directory "servlet". The applet tag I use in the HTML file looks like this:
    <applet
    code="MYAPPLET.class"
    codebase="http://localhost:8080/test/applet classes/"
    <!-- Tell the applet where its peer is located -->
    <param
    name="servlet"
    value="http://localhost:8080/test/servlet/MYSERVLET" />
    </applet>
    Now, when opening the page, the applet can be found but Tomcat gives an error 404 saying that it can not find the servlet. On the other hand, If I make an entry in my web.xml (with url mapping
    <url-pattern>/test </url-pattern> or <url-pattern>/test/servlet </url-pattern>, depending on where I put MYSERVLET)
    for the servlet mentioned above and I put the MYSERVLET in either the WEB-INF/classes directory or in /test/servlet Tomcat gives an error 403. It refuses to connect to the servlet!
    Please can anyone help me. THanx in advance
    debeumers

    You are configuring Tomcat and if you have further questions then post new questions in the forum "Java Servlet Technology".
    Given that your servlet url is "localhost:8080/test/servlet/MyServlet"
    This assumes -
    1) You have created a web application called "test". You have a directory called "test" under- $CATALINA_HOME/webapps
    2) Your html files, jsp files, and subdirectory "applet-classes" (Note - do Not use spaces when naming directories) exist in this top level directory of your web app. If you choose to place your applet classes in this subdir then the codebase can be "applet-classes" - omitting the "/" means this directory is located relative to the current directory of the html file. (No jar files? No archive param then..)
    3) You have a class file called "MyServlet" located - $CATALINA_HOME/webapps/test/WEB-INF/classes
    Some versions of Tomcat require you to uncomment out the area of the Mapping for the Invoker Servlet element in $CAT_HOME/conf/web.xml.
    <servlet-name>invoker</servlet-name>
    <url-mapping>/servlet/*</url-mapping>
    Once this is done, you need not create a directory called "servlet" anywhere in your structure. It is the url mapping.
    You will want to apply url-patterns and mappings to your application specific web.xml (This is located in - $C_H/webapps/test/WEB-INF) when it comes time to deploy the app, but that is not required for testing and development. You need not make changes to the app specific web.xml at this time just to get the servlet to run.
    And finally I suggest you read a book on this subject...

  • Using the servlets with IIS

    hi,
    In a portal project using ASP and IIS server, i need to develop an application which connect to the web and retrieve documents from it.
    I choose a servlet technology to do this.
    I have two question :
    1) If the portal uses IIS can i use Servlets within ASP pages?
    is it necessary to use the package server.jar with IIS, or we can only use IIS ?
    2)Can we connect to an URL page and retrieve it with servlets
    like we do with this portion of code :
    target = new URL(requete);
    HttpURLConnection fetch = (HttpURLConnection)target.openConnection( );
    BufferedReader in = new BufferedReader(new InputStreamReader(fetch.getInputStream( )));
    If yes how ?
    thank you

    Umm, IIS runs ASP pages, which can be written either in VBScript or JScript. Servlets cannot be embedded in or called from within ASP pages. I guess they could be invoked via an HTTP redirect or by creating under-the-hood HTTP connection to the servlet, but that's nasty and circuitous. I'd really recommend finding a way to do what you want in ASP.
    Servlets/JSP's require a Java-based container to run in. There are Servlet containers that work with IIS - check out Tomcat @ jakarta.apache.org
    As for the second question, any Java code can be run from within a Servlet - what's stopping you from using that exact code snippet to do what you want to do?

  • Character encoding in servlet

    Dear colegues,
    I am very new to Servlet technology. I have just made a simply website based on Tomcat 4.1.10 and servlets. I have a files (XML files) encoded in UTF-8 and simply servlet extending VelocityServlet. Servlet just sends the file from the harddrive to the browser. My problem is with encoding. The webpage opened in browser doesn;t have proper encoding of characters (somewhere on the fly the characters written in XMLs are changed to '?'). Does anybody know where to start with this bug ?
    Thanks,
    Wojciech

    Hello,
    you should:
    1) check encoding of readed data from files (if you are not uzsing XML parser).
    2) set http header content type (for html is value "text/html;charset=UTF-8").
    If this remarks do not help, send code of the servlet.
    JM

  • How can I use Servlets on Sun Java System WebServer 6.1

    Hi
    This is Khurram,
    I have just downloaded, and installed "Sun One Java System Web Server 6.1" on WindowsXP. This is installed and working properly on my system. But I want to use Servlet technology on this server, even I did download it just for working on servlets. Before it, I was using typical JavaWebServer2.0 for this purpose.
    Any ways.
    Can any one tell me, how can I do this on "Java System Web Server 6.1".
    Thanks
    any help will be appriciated
    regards
    Khurram

    Thanks for your such action.
    Actually I have installed it since 2 days, and have read throughly the documentation of WebServer, But Only the Link for this purpose is provided "Programmer's Guide to Web Applications", Now I have just searched for it and found only "Programmer's Guide" .PDF format. I have just read it out now, But here also provided a small refference to see "Programmer's Guide to Web Applications". Now I have just the problem that where to find it.
    Please, tell me if you have some solution to my problem
    or atleast tell me where to find the refference "Programmer's Guide to Web Applications". I tried but only found "Programmer's Guide" for Sun Web Server 6.1.
    Thanks any way to give some time.
    Khurram

  • Why jsp is converted into servlet?

    hi,
    Why the jsp is converted into servlet in the container? reason? why cant is evalute as a jsp file itself? why did not they develope a seperate container for jsp?

    hi :-)
    Why the jsp is converted into servlet in the container? reason? why cant is evalute as a jsp file itself?
    JSP is an extension of servlet technology :-)
    why did not they develope a seperate container for jsp?
    Note: (an excerpt from a book)
    "Inside the JSP container is a special servlet called the page compiler.
    The servlet container is configured to forward to this page compiler all HTTP
    requests with URLs that match the .jsp file extension.
    This page compiler turns a servlet container into a JSP container.
    When a .jsp page is first called, the page compiler parses and compiles
    the .jsp page into a servlet class. If the compilation is successful,
    the jsp servlet class is loaded into memory. On subsequent calls,
    the servlet class for that .jsp page is already in memory; however, it could have been updated.
    Therefore, the page compiler servlet will always
    compare the timestamp of the jsp servlet with the jsp page. If the .jsp page
    is more current, recompilation is necessary. With this process, once
    deployed, JSP pages only go through the time-consuming compilation
    process once"
    For more info you can refer to the packages: javax.servlet.jsp and
    javax.servlet.jsp.tagext
    and also the two servlet packages: javax.servlet and javax.servlet.http
    you might be asking why refer to servlet packages? because JSP needs it :-)
    as i mention earlier, JSP is an extension of servlet technology.
    hope other's will also give answer about your question.
    regards,

  • Swing Component to access a Servlet

    Hi All,
    I am new to the technology of java and servlets.
    We have a Web Application which runs on the JSP and Servlet technology using a BEA Weblogic Server.
    User(Client) connects to the server with Login.jsp by providing a valid user-name . The server in returns downloads an Applet from the server . From here-onwards all communications to the server happens via the applet.
    What I want to do is that, I don't want to communicate to the server using the browser and then through applet. Instead I want to write my own application using AWT/SWING and then connect to the server using java.net class.
    I have the code of the Applet and hence I can duplicate it's functionality in "MyApplication".
    Since I have very less experience, in Java related technologies , I just thought I will introduce my idea in this forum. Is this doable. How should I start to get ahead in this. Since the servlets keep throwing HTMLS will I be able to parse them in some so that I can make similar kind of GUI as it comes in the browser window?
    Any information with this regards will be apprecaited.
    Regards,
    Amol

    Hi Jamie,
    Thanks a lot for the quick response.
    My my main question is that are Desktop softwares written to communicate with Web Application Servers.
    is it a workable solution.Are softwares written in that fashion.
    Also how can I call COM server APIs from Java.
    Warm Wishes,
    Amol

  • Error in importing javax.servlet.ServletConfig;

    Hi
    I am fairly new to servlets technology
    while importing package javax.servlet.ServletConfig; i got error Create class "ServletConfig" in package javax.servlet
    I'm using eclipse IDE

    Which project have you created in eclipse?
    Java or J2EE project?
    If its a J2EE project, the jars will be included automatically in the lib
    but if its a Java project, you will have to include the servlet-api.jar in the classpath.

Maybe you are looking for

  • Download file from URL using ADF (urgent help required)

    We have the following requirement: On clicking a button we need to download the file present at a particular location(we have the URL). I have written the following in .jspx file : <af:commandButton  id="btn1" >                     <af:fileDownloadAc

  • Go Live Strategy for CO/MM

    Hi, Please suggest the Go Live strategy for CO / MM especially from Product costing point of view. I have an issue, whether material prices of FG and SFG should be uploaded along with the quantity? 1.Whether, these prices are to be maintained in mate

  • How to Format Annotations in Preview?

    Hi, First of all, if there's a better region of the discussion fora to post this question, please let me know and I'll re-post. I started using Preview.app's annotation tools after I found out that the font format can be adjusted simply pressing Cmnd

  • SSRS passing as Parameter

     I have a table with fields SELECT TOP 1000 [BAT_TYPE]       ,[ITEM_TYPE]   FROM [dbo].[BATT_TYPES] bat_type  item_type 120-M  Batt 54-FM  Batt 45-FM    Batt | | | | commercial Non-Batt fuel            Non-Batt tender          Non-Batt I need to pass

  • Help with Apple Script Code

    Hi, I found this Apple script online and here's how it works: tell application "QuickTime Player" activate try if not (exists document 1) then display dialog "Please open a QuickTime movie." buttons {"Cancel"} default button 1 with icon 1 set thefile