2011-11-13 2 views
1

Spring mvc를 배우기 시작한 jus입니다. 같은 문제에 대해 비슷한 질문을 많이했지만이 오류를 해결할 수는 없습니다. 누군가 내 코드를 살펴보고 누락 된 부분을 알려주실 수 있습니까?Spring MVC Dispatcher 서블릿에서 매핑이 발견되지 않았습니다.

의 web.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> 
    <servlet> 
    <servlet-name>myphotosharingapp</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>myphotosharingapp</servlet-name> 
    <url-pattern>*.htm</url-pattern> 
    </servlet-mapping> 

    <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/myphotosharingapp-service.xml</param-value> 
    </context-param> 

    <welcome-file-list> 
    <welcome-file> 
     jsp/index.jsp 
    </welcome-file> 
    </welcome-file-list> 
</web-app> 

myphotosharingapp-servlet.xml 파일 :

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 

    <!-- mapping --> 
    <bean id="urlMapping" 
     class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
     <property name="mappings"> 
      <props> 
       <prop key="browsefiles.htm">browseFilesController</prop> 
      </props> 
     </property> 
    </bean> 

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

    <bean id="browseFilesController" class="springmvc.controller.BrowseFilesController"> 
     <property name="browseAlbumsService" ref="browseAlbumsService"></property> 
     <property name="methodNameResolver"> 
      <bean 
       class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> 
       <property name="mappings"> 
        <props> 
         <prop key="/browsefiles.htm">browse</prop> 
        </props> 
       </property> 
      </bean> 
     </property> 
    </bean> 

</beans> 

myphotosharingapp-service.xml: 
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 
    <bean name="browseAlbumsService" class="springmvc.service.BrowseAlbumsService"> 
    </bean> 
</beans> 

home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Share Photos</title> 
</head> 
<%-- <% 
     String sourcePath = ("${sourceAlbumPath}" == null)? "" : "${sourceAlbumPath}"; 
%> --%> 

<body> 
    <h1> 
     Welcome   
    </h1> 
    <form name="frmHome" method="Post" action="browsefiles.htm"> 
     <a href=".">View Albums</a> 
     <br> 
     <br> 
     <input type="text" name="sourceAlbumPath" value=""> 
     </input> 
     <button name="Browse" > 
      Browse  
     </button>   
    </form> 
</body> 
</html> 

의 index.jsp :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Share Photos</title> 
</head> 
<body> 
    <h1> 
     Welcome!!   
     <a href="jsp/home.jsp">home</a> 
    </h1> 

</body> 
</html> 
,174,

인덱스 페이지가 잘로드되고 홈 페이지도로드됩니다. 그러나 home.jsp에서 Browse 버튼을 클릭하면 "HTTP STATUS 404"오류가 발생합니다.

Tomcat이 "이름 myphotosharingapp와 디스패처 서블릿에서 [/springmvc/jsp/browsefiles.htm]에 대한 매핑이"

사람이 도와주세요 수 있다고?

답변

1

홈 페이지의 경로는 상대적이며 xml의 매핑이 /browsefiles.htm 인 동안 /jsp/browsefiles.htm을 가리 킵니다.

해결 방법 JSP의 request.getContextPath() 또는 Spring MVC의 <spring:url> JSP 태그를 사용하여 URL을 기준으로 설정하는 것이 해결책입니다.

+0

괜찮습니다 .. 감사합니다 .. – meenakshi

1

귀하의 구성은 /browsefiles.htm을지도하는 것입니다하지만 당신은 /springmvc/jsp/browsefiles.htm를 통해 액세스하려고하는

당신이 정말로 SimpleUrlHandlerMapping를 사용해야합니까? 그렇지 않다면 Spring MVC와 주석에 의한 매핑을 시도해야한다. 훨씬 쉽습니다. 기본 응용 프로그램을 구성하기 위해 두 개의 XML bean 만 필요합니다. 여기에 가장 좋은 튜토리얼입니다 :이 대답없는 것을 이해

http://blog.springsource.org/2011/01/04/green-beans-getting-started-with-spring-mvc/

그러나 나는 봄 주석을 사용하는 방법을 배우고 더 나은 생각합니다. 당신이 새로운 사람들이기 때문에 모르는 경우에 대비하여이 조언을하는 것이 가장 좋습니다.

+0

감사합니다. gigadot. 주석을 사용하는 법을 배웁니다. – meenakshi

관련 문제