Announcement Announcement Module
Collapse
No announcement yet.
web . xml explain Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • web . xml explain

    hi ,

    im new to the spring , can anybody explain the spring context accss in web xml here.

    i have given the servlet content follwing to this web xml

    Thanks you

    fsunjive

    <?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">
    <display-name>Test</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
    <description></description>
    <servlet-name>StudentRegistration</servlet-name>
    <servlet-class>com.company.action.StudentRegistration</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>StudentRegistration</servlet-name>
    <url-pattern>/test.do</url-pattern>
    </servlet-mapping>

    <!--
    <servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>org.springframework.web.context.ContextLoade rServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContexter.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>


    -->


    <servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>org.springframework.web.context.ContextLoade rServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/eapplicationContexter.xml
    </param-value>
    </context-param>


    </web-app>




    ================================================== ========================
    Servlet content
    ================================================== ========================
    import org.springframework.web.context.WebApplicationCont ext;
    import org.springframework.web.context.support.WebApplica tionContextUtils;



    ServletContext servletContext =this.getServletContext();

    WebApplicationContext wac = WebApplicationContextUtils.
    getRequiredWebApplicationContext(servletContext);

    String name = request.getParameter("name");
    int age = Integer.parseInt(request.getParameter("age"));
    String courseName1 = request.getParameter("course1");
    String courseName2 = request.getParameter("course2");
    String courseName3 = request.getParameter("course3");

    StudentService user = (StudentService)wac.getBean("studentService");
    user.save(new Student(age, name));

    CourseService courseService = (CourseService)wac.getBean("courseService");
    courseService.save(new Course(courseName1));
    courseService.save(new Course(courseName2));
    courseService.save(new Course(courseName3));
    Last edited by fsunjive; Jun 3rd, 2010, 11:13 PM.
Working...
X