开发者

Spring mapping problem

开发者 https://www.devze.com 2023-02-09 11:06 出处:网络
I am getting the following error: No mapping found for HTTP request with URI [/my-app] in DispatcherServlet

I am getting the following error:

No mapping found for HTTP request with URI [/my-app] in DispatcherServlet with name 'web'

My web.xml looks like:

<servlet>
  <servlet-name>web</servlet-name>
   <servlet-class>org.springframework.web.servlet.Dispatc开发者_JAVA百科herServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>web</servlet-name>
  <url-pattern>/*</url-pattern>
</servlet-mapping>

And my web-servlet.xml looks like:

<bean name="myController" class="com.app.web.MyController" />

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="viewClass"
         value="org.springframework.web.servlet.view.JstlView" />
  <property name="prefix" value="/WEB-INF/jsp/" />
  <property name="suffix" value=".jsp" />
</bean>

Any help / explanation would be great. Also, what should the view parameter be to new ModelAndView(?) in the controller?

My goal is to be able to hit http://localhost:8080/my-app and be routed to MyController which would then load a given jsp.


Your configuration looks fine to me. In your MyController, make sure you have a request mapping for my-app, like this:-

@Controller
public class MyController {
   @RequestMapping(value="/my-app", method=RequestMethod.GET)
   public String mainPage() {
      return "index";
   }
}

When you call http://localhost:8080/my-app, the server will return the index.jsp from /WEB-INF/jsp/ folder.


Looks like DispatcherServlet is trying to process the request for /my-app, which suggests to me that your web.xml servlet-mapping is directing requests for that space to DispatcherServlet.

You might have something like this?

<servlet-mapping>   <servlet>dispatcher</servlet>   <url-pattern>/*</url-pattern> </servlet-mapping> 

Try calling your controllers with a different extension (.do for example) and update the servlet-mapping to suit

 <servlet-mapping>   <servlet>dispatcher</servlet>   <url-pattern>*.do</url-pattern> </servlet-mapping>

or change /* to /

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消