Using the Spring framework, I create a web application (however, hello world).
I can browse index.jsp without the controller, but
When I implemented the controller, I received an error indicating that the View was not found, and the browser received a 404 error.
It's not a big program, so I'll attach it as it is.
src/main/java/{package}/ActionController.java
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.announcement.RequestMapping;
import org.springframework.web.bind.announcement.RequestMethod;
@ Controller
public class ActionController {
@RequestMapping(value="/hello", method=RequestMethod.GET)
public String hello() {
return "showMessage";
}
@RequestMapping(value="/index", method=RequestMethod.GET)
public String top() {
return "index";
}
}
struts-config.xml
<mvc:annotation-riven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
web.xml (partial)
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern> /<url-pattern>
</servlet-mapping>
src/main/webapp/WEB-INF/view/index.jsp
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
src/main/webapp/WEB-INF/view/showMessage.jsp
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
Below is the log for local debugging.
22:41:42.448 [http-bio-8080-exec-7] DEBUGo.s.web.servlet.DispatcherServlet-DispatcherServlet with name 'dispatcherServlet' processing GET request for [/contextpath/WEB-INF/view/showMessage.jsp]
22:41:42.448 [http-bio-8080-exec-7] DEBUGo.s.w.s.m.a.RequestMappingHandlerMapping-Looking up handler method for path/WEB-INF/view/showMessage.jsp
22:41:42.448 [http-bio-8080-exec-7] DEBUGo.s.w.s.m.a.RequestMappingHandlerMapping-Did not find handler method for [/WEB-INF/view/showMessage.jsp]
22:41:42.449 [http-bio-8080-exec-7] WARNo.s.web.servlet.PageNotFound-No mapping found for HTTP request with URI [/contextpath/WEB-INF/view/showMessage.jsp] in DispatcherServlet with name 'dispatcherServlet'
22:41:42.449 [http-bio-8080-exec-7] DEBUGo.s.web.servlet.DispatcherServlet-Successfully completed request
22:41:42.449 [http-bio-8080-exec-7] DEBUGo.s.web.servlet.DispatcherServlet-Successfully completed request
As far as the above logs are concerned, there is definitely a context path and
As long as you look at the "deployed resources" that appear in the Eclipse specification, you can actually
WEB-INF/view/index.jsp and showMessage.jsp existed.
I also checked if the controller ran through the breakpoint, but
Your request appears to have been accepted.
Why can't I find jsp?
Please give me instructions.
It may not be a definite answer because it is written as follows:
I also checked if the controller ran through the breakpoint, but
Your request appears to have been accepted.
However, there was a log that bothered me.
Is the URL accessed by a browser or something like "/contextpath/hello (for example, http://localhost:8080") "/contextpath/WEB-INF/view/showMessage.js"?
When Spring prints mNo mapping found for HTTP request と, you have accessed the URI (URL) that appears thereafter.In other words, "/contextpath/WEB-INF/view/showMessage.js" now has a request and says Spring has processed it.
When I tried to use the code that omarun posted, Hello World! was displayed.So the code is correct (Spring 4.1.1, Tomcat 8.0.17, JDK 1.8.0_45).
"Also, when I access the URL where ""/contextpath/index2"" does not exist, the following log is printed similar to this phenomenon."
27-Aug-2015 15:54:52.853 WARNING [http-nio-8080-exec-5] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/contextpath/index2] in DispatcherServlet's name'Servlet'Servlet'Servlet's dispatch
After replicating the repository to an external development environment and booting to an existing tomcat8 server, Hello World! was displayed.
After that, I checked again in the environment where I asked the question, but it still didn't start.
The latter environment didn't have much of a development environment, so I reinstalled Eclipse and found it working properly.
"Since the other day, I have received several error notifications from Windows saying ""An exception has occurred inside Eclipse"", and I have not seen any particular problems until now, so I have left it without looking at the details."
There is a possibility that it had some effect this time.
I'm sorry that I don't know the exact cause.
Thank you.
© 2024 OneMinuteCode. All rights reserved.