简体   繁体   English

设置 spring 和 maven

[英]setting up spring and maven

I am creating environment for setting up a spring project using maven , spring.我正在创建使用 maven ,spring 设置 spring 项目的环境。

But i am getting error while trying to execute this URL http://localhost:8080/assignment2_farooqab/WEB-INF/pages/index.jsp[ ^]但是我在尝试执行这个 URL 时出错http://localhost:8080/assignment2_farooqab/WEB-INF/pages/index.jsp[ ^]

The Error is HTTP Status 404 The resource is not available错误是 HTTP 状态 404 资源不可用

I think the problem is due to this file mvcdispather xml我认为问题是由于这个文件 mvcdispather xml

< <

beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        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.2.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.2.xsd">

        <context:component-scan base-package="no.uio.inf5750.assignment2_farooqab" />

        <bean
                class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix">
                        <value>/WEB-INF/pages/</value>
                </property>
                <property name="suffix">
                        <value>.jsp</value>
                </property>
        </bean>

</beans>

basecontroller.java file is basecontroller.java 文件是

package no.uio.inf5750.assignment2_farooqab.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.PathVariable;


@Controller
public class BaseController {

        @RequestMapping(value="/", method = RequestMethod.GET)
        public String welcome(ModelMap model) {

                model.addAttribute("message", "Maven Web Project + Spring 3 MVC - welcome()");

                //Spring uses InternalResourceViewResolver and return back index.jsp
                return "index";

        }

        @RequestMapping(value="/welcome/{name}", method = RequestMethod.GET)
        public String welcomeName(@PathVariable String name, ModelMap model) {

                model.addAttribute("message", "Maven Web Project + Spring 3 MVC - " + name);
                return "index";

        }

}

any tips有小费吗

by your code return "index";通过您的代码return "index"; and your view resolver you forward your view resolver to path和您的视图解析器将您的视图解析器转发到路径

/WEB-INF/pages/index.jsp /WEB-INF/pages/index.jsp

and @RequestMapping annotation is binding this page to website address via value="/" or "/welcome/{name}" so basicly all you have to do is call your application via links并且@RequestMapping注释通过value="/""/welcome/{name}"将此页面绑定到网站地址,因此基本上您要做的就是通过链接调用您的应用程序

http://localhost:8080/assignment2_farooqab or http://localhost:8080/assignment2_farooqab/welcome/test http://localhost:8080/assignment2_farooqabhttp://localhost:8080/assignment2_farooqab/welcome/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM