java - No Mapping Found in HTTP Request with URI [springcodes/functions.jsp] -


before asking new question, have been reading reference , more possibly duplicate questions:

no mapping found http request

i have wasted hours hair-pulling work.

here sample code:

dispatcher-servlet

<context:component-scan base-package="springcodes.controller" />  <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">     <property name="prefix">         <value>/web-inf/views/</value>     </property>     <property name="suffix">         <value>.jsp</value>     </property> </bean> 

web.xml

<servlet>     <servlet-name>dispatcher</servlet-name>     <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>     <load-on-startup>1</load-on-startup> </servlet>  <servlet-mapping>     <servlet-name>dispatcher</servlet-name>     <url-pattern>/</url-pattern> </servlet-mapping>  <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>/web-inf/dispatcher-servlet.xml</param-value> </context-param>  <listener>     <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> 

controller (this controller appears working since index.jsp displays.)

@requestmapping("/welcome") public string displayindex(@requestparam(value="name", required=false, defaultvalue="guestxx") string name, model model) {         model.addattribute("name", name);           // returns view name     return "welcome"; }  @requestmapping("/") public string displayindex2(@requestparam(value="name", required=false, defaultvalue="guesii") string name, model model) {         model.addattribute("name", name);     // returns view name     return "welcome"; } 

controller in question: (when enter url: http://localhost:8080/springcodes/functions.jsp supposed displayed, but not working)

@controller public class functioncontroller {  @requestmapping("/functions") public string displayfunctionspage(model model) {           model.addattribute("funclist", "function list");     // returns view name     system.out.println("are inside?");     return "functions/functionpage";     } } 

there 2 different problems here.

first, have internalresourceviewresolver prefix of /web-inf/views/ (and suffix of .jsp) return should :

return "functions/functionpage"; 

do not repeat prefix nor suffix.

but thing smells. dispatcherservlet mapped /, not /*. if both looks catchall, indeed different :

  • /* means : i want everything - have setup /<mvc:resource> tag allow serving static resources
  • / means : i accept nobody else wanted. allows static resources and jsp outside web-inf folder served directly servlet container.

so servlet container should try serve url http://localhost:8080/springcodes/functions.jsp , not try pass spring dispatcherservlet. if fix first problem, http://localhost:8080/springcodes/functions should work.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -