개발개발자!
94
2016-10-25 15:42:08
4
2487

이클립스 MVC 프로젝트 컨트롤러 관련 질문 입니다.


선배님들 안녕하세요 1년차 개발자 입니다.

웹스퀘어로 개발하다가 JSP로 이제 입문하였는데.. 개발환경설정 때문에 도움을 얻고자.. 글남깁니다.

현재 톰켓 서버 실행 다음 


http://localhost:8080/first로 웹 로그인페이지 로그인 기능을 실행하려고하는데.

a.jax 통신시 컨트롤러를 아예 타지못하고 404에러를 뱉고있습니다

a.jax 통신하는 화면은 기본화면 index.jsp파일에서 띄웠습니다.


$.ajax({

            type: "post",

            url : "http://localhost:8080/first/admin/adminMemSelect",

            data: {

                  user_Id     : adminName,

                  user_Pwd    : adminPass ,

               },

            success: fnAdminSucess,

            error: fnError

 

});

});

----------------------------------------------------------------------------------------------------------------------------

web.xml


<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 

    <welcome-file-list>

        <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>

     

    <!-- Creates the Spring Container shared by all Servlets and Filters -->

    

    <filter>

        <filter-name>encodingFilter</filter-name>

        <filter-class>

            org.springframework.web.filter.CharacterEncodingFilter

        </filter-class>

        <init-param>

            <param-name>encoding</param-name>

            <param-value>utf-8</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>encodingFilter</filter-name>

        <url-pattern>*.do</url-pattern>

    </filter-mapping>

    

    <listener>

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

    </listener>

 

    <!-- Processes application requests -->

    <servlet>

        <servlet-name>action</servlet-name>

        <servlet-class>

            org.springframework.web.servlet.DispatcherServlet

        </servlet-class>

        <init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>

                <!-- /WEB-INF/config/action-servlet.xml,

                /WEB-INF/config/interceptor-servlet.xml -->

            </param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>

        <servlet-name>action</servlet-name>

        <url-pattern>*.do</url-pattern>

    </servlet-mapping>

     

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>classpath*:config/spring/context-*.xml</param-value>

    </context-param>

</web-app>


---------------------------------------------------------------------------------------------------

action-servlet.xml


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:context="http://www.springframework.org/schema/context"

    xmlns:p="http://www.springframework.org/schema/p"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns="http://www.springframework.org/schema/beans"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

 

    <context:component-scan base-package="first"></context:component-scan>

     

    <mvc:interceptors>

        <mvc:interceptor>

            <mvc:mapping path="/**"/>

            <bean id="loggerInterceptor" class="first.common.logger.LoggerInterceptor"></bean>

        </mvc:interceptor>

    </mvc:interceptors>

     

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>

     

    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0" />

    <bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />    

     

    <bean

        class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="1"

        p:viewClass="org.springframework.web.servlet.view.JstlView"

        p:prefix="/WEB-INF/jsp/first/" p:suffix=".jsp">

    </bean>

</beans>

-------------------------------------------------------------------------------------------------------------------------------

server.xml 


<?xml version="1.0" encoding="UTF-8"?>

<!--

  Licensed to the Apache Software Foundation (ASF) under one or more

  contributor license agreements.  See the NOTICE file distributed with

  this work for additional information regarding copyright ownership.

  The ASF licenses this file to You under the Apache License, Version 2.0

  (the "License"); you may not use this file except in compliance with

  the License.  You may obtain a copy of the License at


      http://www.apache.org/licenses/LICENSE-2.0


  Unless required by applicable law or agreed to in writing, software

  distributed under the License is distributed on an "AS IS" BASIS,

  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  See the License for the specific language governing permissions and

  limitations under the License.

--><!-- Note:  A "Server" is not itself a "Container", so you may not

     define subcomponents such as "Valves" at this level.

     Documentation at /docs/config/server.html

 --><Server port="8005" shutdown="SHUTDOWN">

  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>

  <!-- Security listener. Documentation at /docs/config/listeners.html

  <Listener className="org.apache.catalina.security.SecurityListener" />

  -->

  <!--APR library loader. Documentation at /docs/apr.html -->

  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>

  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->

  <Listener className="org.apache.catalina.core.JasperListener"/>

  <!-- Prevent memory leaks due to use of particular java/javax APIs-->

  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>

  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>


  <!-- Global JNDI resources

       Documentation at /docs/jndi-resources-howto.html

  -->

  <GlobalNamingResources>

    <!-- Editable user database that can also be used by

         UserDatabaseRealm to authenticate users

    -->

    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>

  </GlobalNamingResources>


  <!-- A "Service" is a collection of one or more "Connectors" that share

       a single "Container" Note:  A "Service" is not itself a "Container",

       so you may not define subcomponents such as "Valves" at this level.

       Documentation at /docs/config/service.html

   -->

  <Service name="Catalina">


    <!--The connectors can use a shared executor, you can define one or more named thread pools-->

    <!--

    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

        maxThreads="150" minSpareThreads="4"/>

    -->



    <!-- A "Connector" represents an endpoint by which requests are received

         and responses are returned. Documentation at :

         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)

         Java AJP  Connector: /docs/config/ajp.html

         APR (HTTP/AJP) Connector: /docs/apr.html

         Define a non-SSL HTTP/1.1 Connector on port 8080

    -->

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

    <!-- A "Connector" using the shared thread pool-->

    <!--

    <Connector executor="tomcatThreadPool"

               port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    -->

    <!-- Define a SSL HTTP/1.1 Connector on port 8443

         This connector uses the BIO implementation that requires the JSSE

         style configuration. When using the APR/native implementation, the

         OpenSSL style configuration is required as described in the APR/native

         documentation -->

    <!--

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"

               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"

               clientAuth="false" sslProtocol="TLS" />

    -->


    <!-- Define an AJP 1.3 Connector on port 8009 -->

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>



    <!-- An Engine represents the entry point (within Catalina) that processes

         every request.  The Engine implementation for Tomcat stand alone

         analyzes the HTTP headers included with the request, and passes them

         on to the appropriate Host (virtual host).

         Documentation at /docs/config/engine.html -->


    <!-- You should set jvmRoute to support load-balancing via AJP ie :

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">

    -->

    <Engine defaultHost="localhost" name="Catalina">


      <!--For clustering, please take a look at documentation at:

          /docs/cluster-howto.html  (simple how to)

          /docs/config/cluster.html (reference documentation) -->

      <!--

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

      -->


      <!-- Use the LockOutRealm to prevent attempts to guess user passwords

           via a brute-force attack -->

      <Realm className="org.apache.catalina.realm.LockOutRealm">

        <!-- This Realm uses the UserDatabase configured in the global JNDI

             resources under the key "UserDatabase".  Any edits

             that are performed against this UserDatabase are immediately

             available for use by the Realm.  -->

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>

      </Realm>


      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">


        <!-- SingleSignOn valve, share authentication between web applications

             Documentation at: /docs/config/valve.html -->

        <!--

        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />

        -->


        <!-- Access log processes all example.

             Documentation at: /docs/config/valve.html

             Note: The pattern used is equivalent to using pattern="common" -->

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>


      <Context docBase="first" path="/first" reloadable="true" source="org.eclipse.jst.jee.server:first"/></Host>

    </Engine>

  </Service>

</Server>


---------------------------------------------------------------------------------------------------------------

컨트롤러


//--------------------

//로그인사용자정보조회

//--------------------

@RequestMapping(value="/admin/adminMemSelect.do")

@ResponseBody

public int adminMemSelect(CommandMap commandMap, HttpSession session) throws Exception {

System.out.println("1111");

Integer resultInt = 1;

return resultInt;

}


아예 컨트롤러인식이 안되고 있습니다 도움좀시어요 ..ㅠ ㅠ


0
0
  • 답변 4

  • xxrcn11
    1k
    2016-10-25 15:54:14

    ajax 요청 URL을 변경해 보세요


     url : "http://localhost:8080/first/admin/adminMemSelect"

    ->

     url : "http://localhost:8080/first/admin/adminMemSelect.do",

    0
  • 개발개발자!
    94
    2016-10-25 16:04:16

    .do로 해보았는데도 잘안되네요 controller도 리퀘스트맵핑 부분 .do로 맞췄는데 안되어요..


    0
  • xxrcn11
    1k
    2016-10-26 09:14:07

    URL과 매핑의 문제인듯 한데 컨트롤러의 value를 바꿔보시요

    @RequestMapping(value="/first/admin/adminMemSelect.do")

    0
  • 개발개발자!
    94
    2016-11-01 10:04:51

    답변 감사합니다.

    환경설정 쪽에 문제가 있었네요..
     

    감사합니다! 

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.