Announcement Announcement Module
Collapse
No announcement yet.
how to map request url to jsp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to map request url to jsp

    Hi All,

    I am new to Spring framework. I want to write the same functionality of below code in spring framework. This code written in web.xml file of web application.

    <servlet>
    <servlet-name>hello</servlet-name>
    <jsp-file>welcome.jsp</jsp-file>
    </servlet>

    <servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>hello.do</url-pattern>
    </servlet-mapping>

    Can somebody please help me.

  • #2
    Building a web app

    First of all, I understand you are new to Spring framework, but this is not the way to design a web application on the basis of a web.xml.

    You need to have a set of requirements i.e. some Jsp's and their flows and how do you want to build the web application.
    By the way if you want to start on a Web application using spring framework, then refer to the Spring reference documentation.You need to have information with you regarding a your dispatcherservlet,controllers,viewresolver and bean definitons file.
    Cheers,
    Sushant

    Comment


    • #3
      And as far as the topic of the post is concerned, you can map servlet url pattern to jsp using org.springframework.web.servlet.view.InternalResou rceViewResolver class
      and by adding the following property in the bean used for ViewResolver
      <property name="viewClass">
      <value>org.springframework.web.servlet.view.JstlVi ew
      </value>
      </property>
      <property name="prefix">
      <value>/WEB-INF/jsp/</value>
      </property>
      <property name="suffix">
      <value>.jsp</value>
      </property>

      So now if you request for hello.html , the viewResolver will check for hello.jsp in WEB-INF/jsp folder and if the file exists ,it will map the url and will show you the desired page

      Comment


      • #4
        sorry for picking up this old topic. This thread is coming in search results and wanted to add what I had been searching for:
        We can also map a JSP file to request URL by using the translated and compiled .class file corresponding to that JSP. This .class file is placed in the work folder of server by JSP engine. The sample mapping shall look like:

        <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>myServlet_2039227.class</jsp-file>
        </servlet>

        More details: Map Servlet/JSP to URL

        Comment

        Working...
        X