点击链接后无法重定向页面

时间:2015-03-13 04:00:04

标签: java jsp spring-mvc servlets

我是java编程的初学者,但我需要使用spring框架创建一个java程序。 gui已经完成,但是我很难将页面从主页面,修补程序列表重定向到子页面,登录。

我的项目结构

  • SRC
    • 的java
      • 玉米
      • 包名
        • PATCHLIST - //所有java文件作为控制器
    • web应用
      • / WEB-INF
        • /弹簧
        • appServlet
          • servlet的context.xml中
        • 的web.xml

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">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

servlet的content.xml中

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

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>
    <context:component-scan base-package="com.netlinktrust.patchlist" />



</beans:beans>

HomeController.class

    package com.netlinktrust.patchlist;

<import java.util.Locale;
<import org.slf4j.Logger;
<import org.slf4j.LoggerFactory;
<import org.springframework.stereotype.Controller;
<import org.springframework.ui.Model;
<import org.springframework.web.bind.annotation.RequestMapping;
<import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    /**
     * Simply selects the home view to render by returning its name.
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {
        logger.info("Respond Success!", locale);
        return "patchList";
    }

    @RequestMapping(value = "/b", method = RequestMethod.GET)
    public String login(Locale locale, Model model) {
        logger.info("Respond Success!", locale);
        return "login";
    }

    //@RequestMapping(value = "/b", method = RequestMethod.GET)
    //  public String redirect() {
    //      return "redirect:test";
    //  }

    //  @RequestMapping(value = "/test", method = RequestMethod.GET)
    //  public String test() {
    //      return "test";
    //  }
}

patchList.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
    <link href="${pageContext.request.contextPath}/resources/css/steelstyle.css" rel="stylesheet" type="text/css" > 
    <title>View Patch List</title>
</head>
<body >

    <div id = "header">
        <h1>Patch List</h1>
    </div>
    <nav id = "navigation">
         <table border = 2>
             <tr>
                  <ul>
                   <td><li><a href="${pageContext.request.contextPath}/b">Home</a></li></td>
                   <td><li><a href="${pageContext.request.contextPath}/">Patch List</a></li></td>
                   <td><li><a href="${pageContext.request.contextPath}/views/login.jsp">Creating Patch List</a></li></td>
                   <td><li><a href="${pageContext.request.contextPath}/views/login.jsp">DashBoard</a></li></td>
                   <td><li><a href="${pageContext.request.contextPath}/views/login.jsp">Log Out</a></li></td>
                  </ul>
             </tr>
         </table>
    </nav>
<div id="wrapper">
    <div id = "maincontent">
    <table border= 2>
        <tr>
            <th>Issue Id</th><th>SOP</th><th>KSC-ID</th><th>Diversion</th><th>Priority-OLD</th><th>Next Actions</th><th>Title</th><th>Replaced/Clarify/Dependency</th><th>Category</th><th>Avail.Date</th><th>QC Date</th><th>QC Time Taken</th><th>QC</th><th>M And P Date</th><th>M And P Alternative Name</th><th>M And P</th><th>NI State</th><th>Manual Correction</th><th>TS Comments</th><th>KSC Description</th><th>AMO</th><th>AMO</th><th>Item Type</th><th>Path</th>
        </tr>
    </table>  
    </div>
    <div id = "footer">
        &copy; NetLinkTrust 2015
    </div>
</div>
</body>
</html>

的login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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>Testing Page</title>
</head>
<body>
    Link Successful
</body>
</html>

0 个答案:

没有答案