Re: Passing web.xml to a servlet

Hi there,
Why are you writing HTML inside a Servlet?
You can write HTML in a much cleaner and easier way in a JSP page.
Use Servlets only to control the view (JSP Pages) , and to interact with the middle layer Java classes and JavaBeans.
Secondly , please use the Code button, and insert your code inside the opening code and closing code tags.
It makes it easier for us to read and understand your code.

servlet to servlet in same app
request.setAttribute("xml",xmlstr);
RequestDispatcher rd = request.getRequestDispatcher("alias");
rd.forward(request,response);servlet to servlet in different app
URL url = new URL("http://localhost:8080/alias");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.connect();
// send xml
PrintWriter pw = new PrintWriter(con.getOutputStream());
pw.println(xmlstr);
pw.flush();
pw.close();
// get response
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String res = br.readLine();

Similar Messages

  • How to create a simple web.xml for using servlets

    Hello i wanna configure the web.xml that i can use sevlets and beans, but how can i do that?
    This is de directorie i have installed my webapp
    C:\Tomcat 4.1\webapps\testapp
    C:\Tomcat 4.1\webapps\test\WEB-INF\classes (in this dir, I wanna put my beans and servlets, I got one servlet and the name is LogIn.class).
    And i wanna request my servlets with the url http://localhost:8080/testapp/servlet/LogIn
    How can i create a very basic web.xml with working beans, servlets and session? It is for testing-use only, so the security is not important for me at this moment.
    Tnx

    under your web-inf
    in your web.xml file you must map
    the servlets
    under the <web-app> tag type
    <servlet>
         <servlet-name>LogIn</servlet-name>
         <servlet-class>com.LogIn</servlet-class>
    </servlet>
    <servlet-mapping>
          <servlet-name>LogIn</servlet-name>
          <url-pattern>/LogIn</url-pattern>
    </servlet-mapping>ps: start using some IDE such as NetBeans or Ecclipse
    since they will take care of mapping all servlets and Beans
    and generate all the necessary files for your web-app

  • Can i run a servlet without a web.xml file for servlet mapping?

    Hello everyone.
    The code i want to run compiles and everythink looks ok.
    It produces the .class file.
    I run Tomcat 4.1 and i build my Web site with Dreamweaver.
    I have a form in a page and i want to send the data upon form completion to a database i already have build with MySql.
    The database is up and running and the server is set-up ok.
    I have changed the port in Tomcat to run on port 80.
    The directory i have my site is
    Tomcat41\webapps\ROOT\se
    and the directory where i keep the servlet class is
    Tomcat41\webapps\ROOT\se\WEB-INF\servlet
    I have a web.xml file to map the servlet and placed it in
    Tomcat41\webapps\ROOT\se\WEB-INF
    In the Form action i write action:"/servlets/Classes/GroupRegistration"
    and I RECEIVE AN 404 ERROR FROM APACHE.
    Somethink is wrong .
    The following is the code from the GroupRegistration.java file
    and follws the web.xml file.
    Please Help.
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class GroupRegistration extends HttpServlet
    Connection con;
    public void doPost (HttpServletRequest req, HttpServletResponse res)
                             throws ServletException, java.io.IOException
         handleForm(req, res);
    public void init() throws ServletException {
         try{
         /* Loading the driver for the database */
         Class.forName("com.mysql.jdbc.Driver");
         Connection Con = DriverManager.getConnection("jdbc:mysql://localhost/se?user=luser&password=");
         catch (ClassNotFoundException e) {
         throw new UnavailableException("Couldn't load JdbcOdbcDriver");
         catch (SQLException e) {
         throw new UnavailableException("Couldn't get db connection");
         private void handleForm(HttpServletRequest req, HttpServletResponse res)
         throws ServletException {
         //ServletOutputStream out = res.OutputStream();
         //res.setContentType("text/html");
         //Extract the form Data Here
         String group = req.getParameter("GroupNo");
         String Name1 = req.getParameter("Name1");
         String LoginID1 = req.getParameter("LoginID1");
         String Name2 = req.getParameter("Name2");
         String LoginID2 = req.getParameter("LoginID2");
         String Name3 = req.getParameter("Name3");
         String LoginID3 = req.getParameter("LoginID3");
         String Name4 = req.getParameter("Name4");
         String LoginID4 = req.getParameter("LoginID4");
         String URL = req.getParameter("URL");
         String Title2 = req.getParameter("Title2");
         String date = req.getParameter("date");
         String INSERT = "INSERT INTO registration (groupno, name1, loginid1, name2, loginid2, name3, loginid3, name4, loginid4, url, topic, date) VALUES (" + group + "," + Name1 + "," + LoginID2 + "," + Name2 + "," + LoginID2 + "," + Name3 + "," + LoginID3 + "," + Name4 + "," + LoginID4 + "," + URL + "," + Title2 + "," + date + ")";
         PreparedStatement pstmt = null;
         try{
         pstmt = con.prepareStatement(INSERT);
         pstmt.executeUpdate();
         catch (SQLException e) {
         throw new ServletException(e);
         finally {
         try {
         if (pstmt != null)pstmt.close();
         catch (SQLException ignored){
    The web.xml file
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com.xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
    <servlet>
    <servlet-name>GroupRegistration</servlet-name>
    <servlet-class>GroupRegistration</servlet-class>
    </servlet>
    <servlet-maping>
    <servlet-name>GroupRegistration</servlet-name>
    <url-pattern>/myGroupRegistration</url-patern>
    </servlet-mapping>
    </web-app>
    I apreciate your time.
    Thanks for any help.

    and the directory where i keep the servlet class is
    Tomcat41\webapps\ROOT\se\WEB-INF\servletOthers have pointed out that "servlet" should be "classes", but there is another mistake that hasn't been spotted. If you want your servlet to appear in the root context, you should use:
    Tomcat41\webapps\ROOT\WEB-INF\classes
    If you want your servlet to appear under the /se context, then you should use:
    Tomcat41\webapps\se\WEB-INF\classes
    and also, in the latter case, your form action should be /se/myGroupRegistration.

  • Configuring the web.xml to run Servlets

    Hi,
    Can i get some help to configure my web.xml file... ?
    I am trying to run servlets. Do i need to map each servlet i use or can i just create a folder and map the folder. Which web.xml file do i need to change... ? And under which directory shall i place the servlet folder.
    Thanks

    Hi,
    which server ur using ? if its tomcat then this can help u out..
    u have to change the web.xml file in ur own directory.
    for example u have ur directory in tomcat/webapps/<ur directory>
    then in ur directory u have to create 1 WEB-INF directory and copy the web.xml file in that. another thing u have to make 2 direcotries in WEB-INF.
    one is classes - u can keep ur servlets class files + ResourceProperty file
    second is lib - u can keep the library files here
    and u have to register ur each and every servlet in web.xml file
    take care
    enjoy the coading
    kedar

  • Need HELP!! Where I have to place an web.xml(servlet) file on server

    I'm using E-business suite for oracle HR version 11.
    On localhost i have developed an servlet file with using web.xml. On web.xml i have customized the file that can load a class for my servlet.But when I deploy on the server i had a cnfused wher do i have to place web.xml and my servlet.
    I have made an servlet file for my custom. Where do I have to place an xml(servlet) file on server?
    Would you give me know forsolving my problem.Please give me know,I really appreciated if you want to give some solution.
    Regards,
    Dany Fauzi

    Copy web.xml to WEB-INF directory of the web application.

  • Dynamically modifying web.xml

    Hi,
              I am trying to write code that will dynamically add a servlet definition to a deployed application. ie, the deployment descriptor is dynamically edited. In Tomcat, I am able to edit the web.xml file(when the app is exploded) or I can edit the in memory copy and produce a servlet definition on the fly
              I am trying to do the same of Weblogic 8.1. Everything is straightforward as long as the app is exploded, in which case I simply edit the web.xml file..when the app is not exploded, this is not possible. I tried using MBeans to see if I can add a servletRuntimeMBean to a deployed application, but this does not seem possible..looks like these beans are instantiated by the container and there is no handle for developers to create instances of these beans. I was wondering if it was possible to edit the in memory copy of web.xml that the servlet container records. Any suggestions in this regard would be highly welcome
              Thanks, and sorry for the lengthy email!
              Ram

    <taglib>
         <taglib-uri>/mytags</taglib-uri>
         <taglib-location>/mytags.tld</taglib-location>
    </taglib>That means that your tag libaray definition is located at /root/mytags.tld. Some people put them in the WEB-INF, which would make it /root/WEB-INF/mytags.tld.
    The taglib-uri is how you are going to reference it in your JSP. With the above setup, here is how you would reference in your JSP
    <%@ taglib uri="/mytags" prefix="myTagPrefix" %>
    <myTagPrefix:mySpecialTag/>
    Hope this helps.

  • Making changes in web.xml dynamically

    Hi all,
    I have a requirement in which i need to redirect request to com site if it is from desktop browser and to WAP site if request for wap site or from a mobile device
    Have servlet ready doing it but presently taking only to two harcoded URLS of .com and .mobile sites.in web.xml.
    Now i want dynamic changes in web.xml through a servlet to changes those URLs to respective request.
    Thanks in advance,
    dcosta_halo

    The web.xml file is only a data storage file. When a Java Web Server starts up, it read the web.xml file and creates the appropriate objects that live in the JVM and manage parts of the applications hosted by the server. Any changes to the web.xml data file while the server is running are lost once the server is turned off. You need to figure out another design, possibly having the servlet read a database table to get URL strings.

  • 2 web.xml

    can a single appication have 2 web.xml ?
    means first servlet will get entry into one web.xml and second servlet will get entry into another servlet...is that possible ?

    Hello,
    I don't think its possible to have two web.xml file for a single web application, but what you can have is another config.xml file. This becomes equivalent to having STRUTS ................
    Regards
    Gigi Mathew

  • Include another xml file in web.xml

    I was able to use XML Entity to include another xml file in web.xml for older servlet specifications, i.e.:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" [
      <!ENTITY my-web SYSTEM "my-web.xml">
    ]>
    <web-app>
      &my-web;
    </web-app>This allows me to share my-web.xml among various web applications.
    How do I achieve the same thing for servlet specification 2.5, which does not have a DTD but rather an XSD?
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      id="WebApp_ID" version="2.5">I am using Glassfish V2UR1. I know about $domain-dir/config/default-web.xml, but for reasons I won't get into I cannot put things in there.

    Hi Maksim. I understood that. It's just that I would prefer some method that doesn't require the developers to do something like extracting a file from the EAR file, changing the file and then putting it back in. As you probably know, some developers could handle it and some will most certainly make mistakes.
    When they do they come to my group and say "my app doesn't work" and then we have to spend time figuring out why.
    Plus, once the developers get used to doing things the automated way they're going to have a hard time remembering to do a manual step each time they do a build.
    I have heard that there may be some way to do something similar to this on Visual Administrator. I'm going to investigate that too.
    Thanks!
    David.

  • Weblogic.servlet.reloadCheckSecs in web.xml not working

    Given the following web.xml file:
              <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
              1.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
              <web-app>
              <context-param>
              <param-name>weblogic.servlet.reloadCheckSecs</param-name>
              <param-value>100</param-value>
              </context-param>
              <servlet>
              <servlet-name>CookieCounter</servlet-name>
              <servlet-class>servlets.CookieCounter</servlet-class>
              </servlet>
              <servlet-mapping>
              <servlet-name>CookieCounter</servlet-name>
              <url-pattern>monster</url-pattern>
              </servlet-mapping>
              <welcome-file-list>
              <welcome-file>hello.html</welcome-file>
              </welcome-file-list>
              <error-page>
              <error-code>404</error-code>
              <location>/error.jsp</location>
              </error-page>
              </web-app>
              It seems the weblogic.servlet.reloadCheckSecs property is not taking effect.
              The
              default value of -1 is always used. I did stop and restart weblogic.
              I also trid to set the servlet classpath in the web.xml file with
              weblogic.servlet.classpath
              property and it did not change the classpath for the servlet. It seems that
              other
              items are working such as adding new servletrs to the web application. Note
              that
              this is the cookie sample application that installes with the beta 2
              download.
              Thanks,
              Dan.
              

    Hi All:
    Thanks for all your help regarding the adfAuthentication success_url. Now I am able to configure to make this work. But now I am facing another issue i.e. I am getting 401 Not authorized message when the success_url is pointed to the jspx page.
    Note: I am using custom login module similar to DBProcOraDataSourceLoginModule so my roles are stored in the custom Role class. So I am not sure how to pass this role info to the security in ADF in order to authorize the page to be viewed.
    Could you please help and can you point me to any specific link.
    Thanks & Regards
    Sridhar Doki

  • Significance of context param in web.xml to initialize any variable?servlet

    I am writing a standalone web appplication for rss (xml) creation where i am having jsp servlets class etc.
    Now to write rss.xml and read it back in application i have temporarily used c:\\rss.xml but to make it capable working in web application which can be uploaded in website i need to make it configurable i need to kep it in context param of web.xml and in init() method of servlet of my application what exactly i should do there.what i have tried is this :
    public class Startup extends HttpServlet {
    private static String rssFeed;
    private ServletContext ctx;
    Logger log = Logger.getLogger(Startup.class);
    public void init(){
    log.debug("Initializing APPLICATION CONTEXT Variables");
    ctx = getServletContext();
    rssFeed = (String)ctx.getInitParameter("RssFeed");
    log.debug("Rss : " + rssFeed);
    String rssFile = this.getServletContext().getRealPath("") + File.separator + "WEB-INF" + File.separator + "rss.properties";
    Properties property = new Properties();
    try{
    InputStream propertiesFile = new FileInputStream(rssFile);
    property.load(propertiesFile);
    catch (IOException e) {
    log.error("IOException during domainValuesList file Reading");
    e.printStackTrace();
    log.error("Exception while loading AllowedDomainValues file");
    log.debug("Domain Values Lists Updated");
    /** Get Host Name (Server Name) where application is hosted on
    public static String getRssFeed(){
    return rssFeed;
    after that i called this startup servlet class in other servlet taken this getRssFeed()
    stored it as string passed as parametr to other class where i need to call it but there i am getting null pointer exception which says not initialized.
    even what i have written in web.xml is here:
    <context-param>
    <param-name>RssFeed</param-name>
    <param-value>c:\\rsshandler.xml</param-value>
    </context-param>
    <servlet>
    <servlet-name>Startup</servlet-name>
    <servlet-class>src.Startup</servlet-class>
    <init-param>
    <param-name>RssFeedConfig</param-name>
    <param-value>/WEB-INF/rss-config.xml</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>Startup</servlet-name>
    <url-pattern>/Startup</url-pattern>
    <load-on-startup>1</load-on-startup>
    </servlet-mapping>
    i tried what i know or understood but its not working.
    one more thing i have doneis:created rss.properties files in web-inf
    lines added are
    rssfeed=c:\\rsshandler.xml
    but even i am not getting this why
    or what sholud i do here.
    this thing needs to be configurablewhich we can change later easily.
    any suggestions.
    thanks
    vijendra

    Ben -
    There can be init params for the servlet or for the servlet context. For the servlet, this looks like:
    <servlet>
    <servlet-name>InitServlet</servlet-name>
    <servlet-class>package1.InitServlet</servlet-class>
    <init-param>
    <param-name>message</param-name>
    <param-value>Hello From Initialization Parameter</param-value>
    </init-param>
    </servlet>
    in the web.xml file, and is accessed using:
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    message = config.getInitParameter("message");
    For a servlet context init param, you define it as you did using the web.xml settings editor:
    <context-param>
    <param-name>hello</param-name>
    <param-value>hi</param-value>
    </context-param>
    This is accessed using:
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    message1 = config.getServletContext().getInitParameter("hello");
    Hope this helps,
    Lynn
    Java Tools Team

  • Calling servlet with out entry in web.xml

    Hi
    I want to know whether can a servlet be invoked with out having an entry in web.xml.Because to my knowledge when ever an entry is made in teh web.xml the <url-pattern> and the class file will be stored as key value combination it is only then when ever a request is made the server gets the class taht is to be invoked from the <url-pattern> that is passed from the client side.
    Is ther any way by whihc we can call the servlet directly with out an entry in web.xml
    Thanks in advance
    Ajithkumar.S

    Interesting that it is possible on Tomcat anyway.
    What's the real benefit of not having a Servlet
    definied in web.xml?
    The only benefit I see is that
    you don't need to understand/read/change XML when
    adding or removing a servlet. That isn't worth that
    imho. What are the other benefits?The only thing I can think of is , to be able to quickly access a Servlet that you've just written, because it takes additional steps to define it in the web.xml.
    I think it would be a security concern (of some sort) , if the Servlet's class is known, that's why it is better to access a Servlet with a mapping from web.xml

  • Web service and servlets in the same project...web.xml?

    Hello, I have a problem with my web service.
    I have a server, which displays a web service. I programmed this service with JAXRPC.
    I have a client, in another directory. I succeded in compiling, deploying and running the web service.
    The problem is that after I tried to integrate this service in an existing project. This project contains servlets. In these servlets, I'm using sessions.
    These servlets are on the same side as the server of the web service. Because of the implementation of my code, I'd like to use in the class that represents the server of the service, the same session as the one I'm using in the servlets.
    But of course, it's not working by itself. I know there's something to do with the web.xml files.
    The thing is that I created a web.xml file for the service, and another for the servlets.
    I was thinking of joining both of them in one xml file, but everything crashes then...
    Could someone tell me how to create a project with a web service and servlets, and mostly how to configure the xml file??
    Thanks for any help
    Philippe

    Hello, I have a problem with my web service.
    I have a server, which displays a web service. I programmed this service with JAXRPC.
    I have a client, in another directory. I succeded in compiling, deploying and running the web service.
    The problem is that after I tried to integrate this service in an existing project. This project contains servlets. In these servlets, I'm using sessions.
    These servlets are on the same side as the server of the web service. Because of the implementation of my code, I'd like to use in the class that represents the server of the service, the same session as the one I'm using in the servlets.
    But of course, it's not working by itself. I know there's something to do with the web.xml files.
    The thing is that I created a web.xml file for the service, and another for the servlets.
    I was thinking of joining both of them in one xml file, but everything crashes then...
    Could someone tell me how to create a project with a web service and servlets, and mostly how to configure the xml file??
    Thanks for any help
    Philippe

  • JDev 10.1.3 compile error in servlet 2.4 web.xml

    I built a Servlet 2.4/JSP 2.0 application in JDev 10.1.3. When I try to make/compile/deploy it the compiler gives me errors like the following for every JSP file that has a JSTL 1.1 taglib:
    Error(2,9): Element "web-app' used but not declared
    Error(2,63): Attribute 'xmlns:xsi' used but not declared
    Error(3,103): Attribute 'xsi:schemaLocation' used but not declared
    Error(4,16): Attribute 'version' used but not declared
    Error(4,56): Attribute 'xmlns' used but not declared
    Error(4,57): Can not build schema 'http://java.sun.com/xml/ns/j2ee' located at 'http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd'
    Error(5,15): Element 'description used but not declared
    It is obviously havng problems with the web.xml file (which is in the servlet 2.4 format) and is probably not finding the web.xml DTD document. How do I fix it?
    Installation is on Solaris 9 using J2SDK 1.4.2_04-b05
    By the way, this system is on a disconnected network. How do I get JDeveloper updates for a system not connected to the Internet?

    Allen,
    A JSP with web.xml web-app element
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee">
    runs in JDeveloper 10.1.3
    thanks,
    Deepak

  • Help needed in Mapping servlet in web.xml file

    Hi Can anyone please tell me what am doing wrong here. I can't see this servlet in my url. Please help.
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
         <servlet-class>HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/com/jci/fi/application/eems/HelloWorld/*</url-pattern>
    </servlet-mapping>
    package com.jci.fi.application.eems;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloWorld extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<body>");
    out.println("<head>");
    out.println("<title>Naveen Wants to goto TollyWood......!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Hello World!</h1>");
    out.println("</body>");
    out.println("</html>");

    your web.xml shoould be something like this...
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>com.jci.fi.application.eems.HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>HelloWorld</url-pattern>
    </servlet-mapping>
    Hope this helps..
    CK

Maybe you are looking for

  • Voice Memos Issue - 3GS

    I have an iPhone 3GS and I've had it for about a month. I have a band and we rehearse in a small storage space. I'd like to use my iPhone to record our rehearsals for when we come up with something good. Our first rehearsal, everything worked fine (t

  • My iMac freezes when updating my apps in iTunes

    My iMac is a 24" with 3,06GHz Intel Core 2 Duo and 4GB 800MHz DDR2 RAM. After the installation of Lion, every time I try to download the updated apps inside iTunes (yes, it happens just with iTunes since the Lion installation!) after one or two minut

  • 64-bit Windows Vista USB synchronization

    Is Palm developing a fix for 64-bit Windows Vista USB synchronization? Or is Bluetooth the only option?  jk Post relates to: Palm TX

  • HT1577 I tried to download a complete season of a tv show and it mucked up my computer. How can I get rid of it?

    I tried to download a complete season of a Tv show and it slowed down my computer to the point where it was completely unuseable. How can I get rid of this series/

  • CRASHING LIKE MAD

    My InDesign CS6 is crashing like mad.  AND I am finding DBSharingShield files on my desktop. Along with files that look like they are suppose to reopen aftr a crash.  BUT MY ORIGINAL FILES ARE CORRUPTING, AND I AM HAVING TO SAVE NEW FILE NAMES.  If I