0

I have a litte weird problem with java spring mvc. When user wants to go "localhost:8080/admin" everything works fine but when user wants to go "localhost:8080/admin/create", all CSS and JS files will be missing.

ADMIN CONTROLLER

@Controller
@RequestMapping(value="/admin")
public class AdminController {

    @Autowired
    private JobService jobService;

    @RequestMapping(path="")
    public String index(){
        return "admin";
    }

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

    @RequestMapping(path = "/create", method = RequestMethod.POST)
    public @ResponseBody String create(@RequestParam String title, @RequestParam String description,@RequestParam int personQuantity, @RequestParam String lastApp) {

        Job newJob = new Job();
        newJob.setJobTitle(title);
        newJob.setJobDescription(description);
        newJob.setNumberOfPersonToHire(personQuantity);
        newJob.setLastApplicationDate(lastApp);

        jobService.create(newJob);
        return "admin";
    }
}

WEB.XML

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>Kodgemisi-HR-Application-master</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

/admin

/admin/create

File Order

1 Answer 1

1

I found the solution

<link href="/css/index.css" rel="stylesheet"></link>
<link href="/css/bootstrap.min.css" rel="stylesheet"></link>
<script src="/js/jquery-3.2.1.js"></script>
<script src="/js/bootstrap.min.js"></script>

ADD / to paths of js and css which written inside the html

Spring mvc: css does not work when adding slash at the end of URL

Sign up to request clarification or add additional context in comments.

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.