Spring中的Hello World未运行

时间:2016-07-25 08:31:45

标签: spring jsp spring-mvc http-status-code-404

我是春天的初学者。 试图运行一个简单的" Hello World"项目 使用Netbeans IDE 8.1,Glassfish 4.1

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="index.jsp">indexController</prop>
        </props>
    </property>
</bean>

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />

<!--
The index controller.
-->
<bean name="indexController"
      class="org.springframework.web.servlet.mvc.ParameterizableViewController"
      p:viewName="index" />

的web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>

的index.jsp

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Example :: Spring Application</title>
</head>
<body>
    <form:form  method="POST" action="addph">
        <form:label path="name">Name</form:label>
        <form:input path="name"></form:input>
    </form:form>
</body>

当我运行代码时,浏览器无法找到该页面。 显示错误。 有什么我想念的吗?

1 个答案:

答案 0 :(得分:0)

欢迎文件设置为web.xml中的index.jsp

Sub ModifyHyperlinks()
    Dim link As Hyperlink
    For Each link In ActiveDocument.Hyperlinks
        link.Address = Replace(link.Address, "q1=", "q1=field1")
        link.Address = Replace(link.Address, "q2=", "q2=field2")
    Next
End Sub