springMVC 无法访问controller 跪求大神解答

水三千 发布于 2014/05/10 11:59
阅读 7K+
收藏 0

访问部到Controller,,求大神解答。。坐等!


pring mvc.xml配置

<?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns="http://www.springframework.org/schema/beans"  
 xmlns:context="http://www.springframework.org/schema/context"  
 xmlns:p="http://www.springframework.org/schema/p"  
 xmlns:mvc="http://www.springframework.org/schema/mvc"  
 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-3.0.xsd  
      http://www.springframework.org/schema/context  
      http://www.springframework.org/schema/context/spring-context.xsd  
      http://www.springframework.org/schema/mvc  
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
     <!-- 注解扫描包 -->
    <context:component-scan base-package="com.yupeng.xcs.website.com.yupeng.controller" />
    <context:annotation-config />

    <mvc:annotation-driven />

    <mvc:default-servlet-handler/>
    <!-- 静态资源访问 -->
     <mvc:resources location="/res/website/img/" mapping="/img/**"/>  
     <mvc:resources location="/res/website/js/" mapping="/js/**"/>   
    

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

 </beans> 

spring 配置:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"    
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    
 <!-- 注解支持 -->
 

    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName"
            value="com.mysql.jdbc.Driver">
        </property>
        <property name="url" value="jdbc:mysql://localhost/Xcs?useUnicode=true&amp;characterEncoding=utf-8"></property>
        <property name="username" value="root"></property>
        <property name="password" value="12345"></property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                </prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        <property name="configLocations">
            <list>
                <value>
                    classpath*:com/yupeng/xcs/website/hibernate/hibernate.cfg.test.xml
                </value>
            </list>
        </property>
    </bean>
    
    

    
        <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    
    <bean id="transactionBese" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true" abstract="true">
        <property name="transactionManager" ref="transactionManager"></property>
        <property name="transactionAttributes">
            <props>
                <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="modify*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="get*">PROPAGATION_NEVER</prop>
            </props>
        </property>
    </bean>    
    <tx:annotation-driven transaction-manager="transactionManager"
        proxy-target-class="true" />   

    
    </beans>

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">
  <display-name></display-name>    
 
  <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath*:config/springAnnotation-spring.xml</param-value>
  </context-param>
 
 
  <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
 
  <servlet>
      <servlet-name>springMVC</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <init-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>classpath*:config/springAnnotation-servlet.xml</param-value>
          </init-param>
       <load-on-startup>1</load-on-startup>
  </servlet>
 
     <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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <!-- encoding filter for jsp page -->
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
  <servlet-mapping>
      <servlet-name>springMVC</servlet-name>
      <url-pattern>*.do</url-pattern>
  </servlet-mapping>
 
 
 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

index.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
 
  <body>
    <form action="add/adduser.do">
        Username:<input type="text" name="username"/><br/>      
        password:<input type="text" name="password"/><br/>
        <input type="submit" value="submint"/>
    </form>
  </body>
</html>

UserController.java :

package com.yupeng.xcs.website.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yupeng.xcs.website.entity.User;
import com.yupeng.xcs.website.service.IUserMng;

@Controller
@RequestMapping("/User")
public class UserController {
    

    private IUserMng userMng;
    
    
    @RequestMapping("/adduser.do")
    public String adduser(User user){
        System.out.println("112312312");
        userMng.add(user);
        return "login";
        
    }
    @RequestMapping("/login")
    public String login(User user){
        userMng.login(user);
        return "index";
    }

    
    public IUserMng getUserMng() {
        return userMng;
    }
    @Resource(name="userMng")
    public void setUserMng(IUserMng userMng) {
        this.userMng = userMng;
    }

    
    
}

 


加载中
0
Lukewxl
Lukewxl

注解扫描包的配置对吗?usercontroller的package

水三千
对不起对不起,是我自己粗心大意,谢谢你的帮忙。。非常感谢。
0
泥瓦匠BYSocket
泥瓦匠BYSocket

<!-- 注解扫描包 -->

    <context:component-scan base-package="com.yupeng.xcs.website.com.yupeng.controller" />


UserController.java :

package com.yupeng.xcs.website.controller;


这两个路径 看清楚

多了个 yupeng 

水三千
嗯嗯,看到了,怪我自己太粗心了,谢谢你的帮忙,真是不好意思啊。。
返回顶部
顶部