抱歉,我的英语很差,以下是我的代码。
的web.xml
输入" http://localhost:8080/mvc/hello"
我刚收到请求的资源不可用。 http状态404
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
用SpringMVC-servlet.xml中
<context:component-scan base-package="hello.*"/>
<!-- don't handle the static resource -->
<mvc:default-servlet-handler/>
<!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven />
<!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
mycontrol here is my simple control
package hello;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/mvc")
public class mvcControl {
@RequestMapping("/hello")
public String sayhello() {
System.out.println("show_hello");
return "hello";
}
}
还有其他人:
代码结构体
http://i.stack.imgur.com/6HBxq.png
登录intellij
/Users/fushenshen/Desktop/Collection/apache-tomcat-8.0.33/bin/catalina.sh run
[2016-04-16 05:36:31,547] Artifact HelloWeb:war exploded: Server is not connected. Deploy is not available.
16-Apr-2016 17:36:32.860 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.33
16-Apr-2016 17:36:32.865 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Mar 18 2016 20:31:49 UTC
16-Apr-2016 17:36:32.865 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.33.0
16-Apr-2016 17:36:32.865 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Mac OS X
16-Apr-2016 17:36:32.865 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.11.4
16-Apr-2016 17:36:32.865 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x86_64
16-Apr-2016 17:36:32.866 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre
16-Apr-2016 17:36:32.867 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_40-b27
16-Apr-2016 17:36:32.867 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
16-Apr-2016 17:36:32.867 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /Users/fushenshen/Library/Caches/IntelliJIdea2016.1/tomcat/Unnamed_HelloWeb
16-Apr-2016 17:36:32.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /Users/fushenshen/Desktop/Collection/apache-tomcat-8.0.33
16-Apr-2016 17:36:32.871 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/Users/fushenshen/Library/Caches/IntelliJIdea2016.1/tomcat/Unnamed_HelloWeb/conf/logging.properties
16-Apr-2016 17:36:32.872 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
16-Apr-2016 17:36:32.872 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
16-Apr-2016 17:36:32.875 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
16-Apr-2016 17:36:32.875 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
16-Apr-2016 17:36:32.875 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
16-Apr-2016 17:36:32.876 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
16-Apr-2016 17:36:32.876 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=/Users/fushenshen/Desktop/Collection/apache-tomcat-8.0.33/endorsed
16-Apr-2016 17:36:32.876 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/Users/fushenshen/Library/Caches/IntelliJIdea2016.1/tomcat/Unnamed_HelloWeb
16-Apr-2016 17:36:32.876 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/Users/fushenshen/Desktop/Collection/apache-tomcat-8.0.33
16-Apr-2016 17:36:32.877 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/Users/fushenshen/Desktop/Collection/apache-tomcat-8.0.33/temp
16-Apr-2016 17:36:32.877 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/fushenshen/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
16-Apr-2016 17:36:33.216 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
16-Apr-2016 17:36:33.282 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
16-Apr-2016 17:36:33.288 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
16-Apr-2016 17:36:33.298 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
16-Apr-2016 17:36:33.299 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1103 ms
16-Apr-2016 17:36:33.366 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
16-Apr-2016 17:36:33.367 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.33
16-Apr-2016 17:36:33.381 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
16-Apr-2016 17:36:33.414 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
16-Apr-2016 17:36:33.416 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 116 ms
Connected to server
[2016-04-16 05:36:33,777] Artifact HelloWeb:war exploded: Artifact is being deployed, please wait...
[2016-04-16 05:36:34,190] Artifact HelloWeb:war exploded: Artifact is deployed successfully
[2016-04-16 05:36:34,191] Artifact HelloWeb:war exploded: Deploy took 414 milliseconds
16-Apr-2016 17:36:43.386 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /Users/fushenshen/Desktop/Collection/apache-tomcat-8.0.33/webapps/manager
16-Apr-2016 17:36:43.423 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /Users/fushenshen/Desktop/Collection/apache-tomcat-8.0.33/webapps/manager has finished in 36 ms
答案 0 :(得分:0)
你说:
输入&#34; http://localhost:8080/mvc/hello&#34;。我刚收到请求的资源不可用。 http状态404。
在您的评论中,您说您的网络应用程序名称是HelloWeb,并且它正在tomcat中部署为localhost:8080 / HelloWeb /。尝试访问以下网址:
http://localhost:8080/HelloWeb/mvc/hello
如果可以,那么您可以将IntelliJ中的Web应用程序的应用程序上下文配置为/并访问原始URL:
http://localhost:8080/mvc/hello
您在构建配置中更改IntelliJ中的应用程序上下文: