jeudi 12 mars 2015

Cannot redirect page when i click on a link

I am a beginner in java programming but i am required to create a java programme using spring framework. The gui is done already but i am having difficulty in redirecting pages from the main page, Patch List, to the sub page, login.


my project structure



  • src

    • main

    • java

      • com

      • packagename

        • patchlist -//all java files as controller





    • webapp

      • /WEB-INF

        • /spring

        • appServlet

          • servlet-context.xml



        • web.xml








web.xml file



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://ift.tt/nSRXKP"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/nSRXKP <http://ift.tt/LU8AHS">

<!-- 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://ift.tt/1bHqwjR"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:beans="http://ift.tt/GArMu6"
xmlns:context="http://ift.tt/GArMu7"
xsi:schemaLocation="http://ift.tt/1bHqwjR <http://ift.tt/1fmimld
<http://ift.tt/GArMu6 <http://ift.tt/1jdM0fG
<http://ift.tt/GArMu7 <http://ift.tt/1jdLYo7">

<!-- 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://ift.tt/QfKAz6" 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://ift.tt/kTyqzh">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Testing Page</title>
</head>
<body>
Link Successful
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire