0

I know this is a repeated question but I was not able to fix problem by looking into another question's solution. However I have done all that was suggested in previous question.
An that is why I am asking the question with my code please see what is wrong with my code.
My web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>HMSLoginMVCSpring</display-name>
  <servlet>
     <servlet-name>spring-dispatcher</servlet-name>
     <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
     </servlet-class>
 </servlet>
 <servlet-mapping>
     <servlet-name>spring-dispatcher</servlet-name>
     <url-pattern>/</url-pattern>
 </servlet-mapping>
</web-app>  

my dispatcher

    <?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  http://www.springframework.org/schema/cache 
        http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">


   <context:component-scan base-package="com.java.Package.Login"></context:component-scan>

   <mvc:annotation-driven/>
    <mvc:resources mapping="/resources/**" location="/resources/theme/" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix">

            <value>/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>


</beans>  

My controller class

 package com.java.Package.Login;

import java.util.Map;

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

@Controller
public class LoginController {
    @RequestMapping(value="/Login.html", method=RequestMethod.GET)
    public ModelAndView getLoginForm(){
        ModelAndView model = new ModelAndView("Login");
        return model;

    }
    @RequestMapping(value="/submitForm.html", method=RequestMethod.POST)
    public ModelAndView getData(@RequestParam Map<String,String> loginData){
        String loginId= loginData.get("LoginId");
        String password= loginData.get("Password");
        ModelAndView model = new ModelAndView("Login");
        if(loginId.equals("vipul")&& password.equals("singh")){
            model.addObject("SucessMsg", "Your are authorised user and your user Id is "+loginId+" and password is "+password);         
        }
        else{
            model.addObject("SucessMsg","Wrong Login Id and Password");
        }

        return model;

    }
}

My LoginPage

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<!DOCTYPE Html>
<html lang="en">
<title>Aventyn&reg;| Login</title>
    <head>
        <link type="text/css" rel="stylesheet" href='<spring:url value="/resources/css/bootstrap.min.css" />' >
        <link type="text/css"  rel="stylesheet" href='<spring:url value="/resources/css/loginCSS.css" />'>



    </head>
    <body>
        <div class="container-fluid">
            <form action="http://localhost:8087/HMSLoginMVCSpring/submitForm.html" method="post">
            <div class="row margin_Div">
                <div class="col-sm-12">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            <h2 class="panel-title text-center"><strong>Login Page</strong></h2>
                        </div>
                        <div class="panel-body">  
                            <div class="row">
                                <div class="col-sm-3 col-md-2">
                                    <b>Login Id:</b>
                                </div>
                                <div class="col-sm-4 col-md-3">
                                    <div class="input-group">
                                        <span class="input-group-addon">*</span>
                                        <input type="text" class="form-control input-sm" placeholder="LoginId" name="LoginId">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-3 col-md-2">
                                    <b>Password:</b>
                                </div>
                                <div class="col-sm-4 col-md-3">
                                    <div class="input-group">
                                        <span class="input-group-addon">*</span>
                                        <input type="text" class="form-control input-sm" placeholder="Password" name="Password">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-3 col-md-2"></div>
                                <div class="col-sm-4 col-md-3">
                                    <button class="form-control btn-sm btn-primary" type="submit">Login</button>
                                    </div>
                                </div>
                                <div class="row">
                                <div class="col-sm-12">
                                    <p>${SucessMsg}</p>
                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            </div>


    </body>
    <script type="text/javascript" src='<spring:url value=" /resources/js/jquery.min.js"/>'></script>
    <script type="text/javascript" src=' <spring:url value="/resources/js/bootstrap.min.js"/>'></script>
</html>

I have placed my ccs file as
resource folder having css and js

I dont know where i am wrong, my page loads without css and when I go to view page source and click on the css link it it shows resource not found.

Please check what is wrong.

2 Answers 2

1

You should move resources folder from webapp into WebContent, which is for sure the web content folder which is packaged to the webapp.

- WebContent
     - META-INF
     - resources
          - theme
               ...
     - WEB-INF
Sign up to request clarification or add additional context in comments.

Comments

0

Your path should be

<link type="text/css"  rel="stylesheet" href='<spring:url value="/resources/theme/css/bootstrap.min.css" />'>
<link type="text/css"  rel="stylesheet" href='<spring:url value="/resources/theme/css/loginCSS.css" />'>

Please add "/theme".

Hope this help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.