facebook

what web.xml needs to instantiate a servlet in a Spring

  1. MyEclipse Archived
  2.  > 
  3. Documentation
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #252977 Reply

    amir55
    Participant

    hi dear
    just to make life easy. I will copy the problem. three files.

    1 – JavaClient is working perfect it is from internet tutorial
    ***************************************
    public class JavaClient
    {

    public static void main(String args[]) throws Exception
    {
    try
    {
    System.out.println(“point1”);
    Resource res = new ClassPathResource(“hello.xml”);
    System.out.println(“point2”);
    BeanFactory factory = new XmlBeanFactory(res);
    System.out.println(“point3”);
    Hello bean1 = (Hello) factory.getBean(“hello”);
    // String s = bean1.sayhello(args[0]);
    String s = bean1.sayhello(“Amir”);
    System.out.println(s);
    }catch(Exception e1){System.out.println(“”+e1);}
    }
    }
    **************************************************
    2 – ServletClient from the internet not working as it misses web.xml

    public class ServletClient extends HttpServlet
    {
    public void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException
    {
    resp.setContentType(“text/html”);
    PrintWriter out =resp.getWriter();
    String a = req.getParameter(“text1”);
    try
    {
    System.out.println(“point1”);
    Resource res = new ClassPathResource(“hello.xml”);
    System.out.println(“point2”);
    BeanFactory factory = new XmlBeanFactory(res);
    System.out.println(“point3”);
    Hello bean1 = (Hello)factory.getBean(“hello”);
    String s = bean1.sayhello(a);
    out.println(s);
    }catch(Exception e1){System.out.println(“”+e1);}
    }
    }

    3 – web.xml that I attempted to create which the one needs yuor attention and correction

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <web-app version=”2.4″
    xmlns=”http://java.sun.com/xml/ns/j2ee&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”&gt;
    <servlet>
    <servlet-name>helloProject</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    <servlet>
    <servlet-name>ServletClient</servlet-name>
    <servlet-class>test.ServletClient</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ServletClient</servlet-name>
    <url-pattern>/ServletClient</url-pattern>
    </servlet-mapping>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>hello.xml</param-value>
    </context-param>
    <servlet>
    <servlet-name>SpringContextServlet</servlet-name>
    <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
    </servlet>

    <!–listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener–>
    </web-app>

    ***********************************************

    or I can zip u the whole program if u do not mind

    thnaks a lot

    #253024 Reply

    Riyad Kalla
    Member

    You need to ask your question in more detail, I don’t understand what you are requesting.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: what web.xml needs to instantiate a servlet in a Spring

You must be logged in to post in the forum log in