有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javastsuite和springwebmvc

我将spring 4.1.6与STSuite、Tomcat v8一起使用

enter image description here

网络。xml是:

> <?xml version="1.0" encoding="ISO-8859-1"?>
  <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">
    <display-name>SpringMVC6</display-name>    
   <!--- Location of the XML file that defines the root application context.
    Applied by ContextLoaderListener.   -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/application-config.xml</param-value>
    </context-param>

    <listener>
        <listener-          class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>    
    <!--
        - Servlet that dispatches request to registered handlers (Controller implementations).
    -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/mvc-servlet.xml</param-value>
        </init-param> 
        <load-on-startup>1</load-on-startup>
    </servlet>

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

</web-app>

应用程序配置。由spring web项目创建的xml:-

enter image description here

mvc配置。位于WEB-INF/config中的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:mvc="http://www.springframework.org/schema/mvc"   xmlns:context="http://www.springframework.org/schema/context"   xmlns:tx="http://www.springframework.org/schema/tx"     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      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

     <!-- Uncomment and your base-package here:  -->
         <context:component-scan
            base-package="com.sat.controllers"/>


    <mvc:annotation-driven />

    <bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/view/showMessage.jsp'    -->

            <property name="prefix" value="/WEB-INF/view/"/>
            <property name="suffix" value=".jsp"/>  </bean>

</beans>

索引。jsp是:

> > 
<!DOCTYPE html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
     <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ >taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<html>  <head>      <meta charset="utf-8">      <title>Welcome</title>
    </head>     <body>
            <%-- <c:url value="hello.jsp" var="message" /> --%>  <a > <href="./WEB-INF/view/hello.jsp">Click to enter</a>   </body> </html>

你好。jcp是

%@ 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>Hello JSP</title>
</head>
<body>

 Hello  $(message)
</body>
</html>

我在src/main/java下的HelloController类是:

package com.sat.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller


public class HelloController {

    @RequestMapping(value= "/hello", method = RequestMethod.GET )

    public ModelAndView sayHello(Model model){

         String message="hello from controller";

        return new ModelAndView("hello", "message", message);



    }

}

我得到了索引。带有“点击进入”超链接的jsp,但当我点击它时,它什么也不带

错在哪里


共 (1) 个答案

  1. # 1 楼答案

    在你的索引中尝试以下内容。jsp:

    <a href="hello">
    

    而不是

    <a href="./WEB-INF/view/hello.jsp">