ourenhou 2017-10-18 13:56 采纳率: 0%
浏览 3027
已结题

springmvc 跳转的jsp页面引用其他页面报错404

做了开发几年了,突然发现自己啥都不会。借着别人的项目学习学习。
spring-mvc.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"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:c="http://www.springframework.org/schema/c"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">

    <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
    <context:component-scan base-package="com.gray"> 
            <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> 
    </context:component-scan> 
    <aop:aspectj-autoproxy proxy-target-class="true">
        <aop:include name="controllerAspect"/>
    </aop:aspectj-autoproxy>

<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
    <bean id="folderjsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value="" /><!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->
    </bean>
    <bean id ="foldermain" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/main/" />
        <property name="suffix" value="" /><!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->
    </bean><!--

      html视图解析器 必须先配置freemarkerConfig,注意html是没有prefix前缀属性的
    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">  
        <property name="templateLoaderPath">  
            <value>/WEB-INF/jsp/main/</value>  
        </property>  
    </bean>  
     <bean id="htmlviewResolver"  
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">  
        <property name="suffix" value=".html" /> 
        <property name="order" value="0"></property> 
        <property name="contentType" value="text/html;charset=UTF-8"></property>         
    </bean>  

--></beans>

spring-mybatis.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"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:c="http://www.springframework.org/schema/c"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">
    <!-- 引入属性文件 -->
    <context:property-placeholder location="classpath:spring/jdbc.properties" />
    <!-- 自动扫描(自动注入) -->
    <context:component-scan base-package="com.gray.*.service" />
    <!-- 配置数据源 -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${db.driver}"></property>
    <property name="url" value="${db.url}"></property>
    <property name="username" value="${db.username}"></property>
    <property name="password" value="${db.password}"></property>
    </bean>

    <!-- myBatis文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
        <property name="configLocation" value="classpath:spring/mybatis-config.xml" />
        <property name="mapperLocations" value="classpath:spring/mybatis.xml" />
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage"  value="com.gray.*.dao" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- 配置事物的注解方式注入 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>  

    <bean id="sqlSession"     class="org.mybatis.spring.SqlSessionTemplate">   
          <constructor-arg index="0" ref="sqlSessionFactory" />   
          <constructor-arg index="1" value="BATCH" />  
     </bean>  

</beans>

controller.java

package com.gray.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gray.user.entity.User;
import com.gray.user.service.impl.UserServiceImpl;


@Controller
@RequestMapping("/main")
public class loginController {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/dologin.do")
    public String dologin(User user, Model model){
        boolean isLogin = false;
        System.out.println("call doUserLogin");
        isLogin = userService.doUserLogin(user);
        if (isLogin) {
            System.out.println("用户名密码正确");

            //跳转到主页面
            return "main/main.jsp";
        }else {
            model.addAttribute("message", "用户名或者密码错误");

            return "/fail.jsp";//返回的页面

        }
    }

    /**
     * 账户密码输入错误的页面跳转
     * @return 登录页面
     */
    @RequestMapping("/backIndex.do")
    public String backIndex(){
        return "index.jsp";
    }
}


主页面index.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生管理系统</title>
<link rel="stylesheet" href="/WEB-INF/css/style.css"/>
<link rel="stylesheet" href="/WEB-INF/css/select.css"/>
</head>
<body>
    <div id="clouds" style="font-size: 35px; text-align: center;">
        学生管理系统
        <div class="cloud x1"></div>
        <div class="cloud x2"></div>
        <div class="cloud x3"></div>
        <div class="cloud x4"></div>
        <div class="cloud x5"></div>
    </div>
    <div class="container" >
        <div id="login">
            <form method="post" action="main/dologin.do" method="post">
                <fieldset class="clearfix">
                    <span class="fontawesome-user"></span>
                    <input type="text" name="username" placeholder="UserId">
                     <span class="fontawesome-lock"></span>
                        <input name="password" type="password" placeholder="PassWord">
                         <input type="submit" value="登录">
                </fieldset>
            </form>
        </div>
    </div>
</body>
</html>

要跳转的页面maiin.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>信息管理系统</title>
</head>
<frameset rows="88,*" cols="*" frameborder="no" border="0" framespacing="0">
  <frame src="/WEB-INF/jsp/top.jsp" name="topFrame" scrolling="no" noresize="noresize" id="topFrame" title="topFrame" />
  <!--<frameset cols="187,*" frameborder="no" border="0" framespacing="0">
    <frame src="left.html" name="leftFrame" scrolling="no" noresize="noresize" id="leftFrame" title="leftFrame" />
    <frame src="index.html" name="rightFrame" id="rightFrame" title="rightFrame" />
  </frameset>
-->
</frameset>
<noframes><body>
</body></noframes>
</html>

跳转之后的页面图片说明

  • 写回答

7条回答

  • daqiaoxia 2017-10-19 02:13
    关注

    //跳转到主页面
    return "main/main.jsp";
    改成
    //跳转到主页面
    return "main.jsp";

    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services