Voglio includere file js e css nel mio jsp, ma non sono in grado di farlo. Sono nuovo del concetto di MVC primaverile. Per molto tempo, ho lavorato su questo stesso argomento. Il mio indice di pagina è come questoCome includere js e CSS in JSP con Spring MVC
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/style.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/LoginPageScrip.js">
</script>
<style type="text/css">
body {
background-image: url("LoginPageBackgroundImage.jpg");
}
</style>
</head>
<body >
<h6>Please login in google Chrome</h6>
<h1 align="center">Welcome to my Twitter Clone</h1>
<div class="m" style="margin-left: 401px; margin-top: 70px;">
<form method="post" action="LoginForExistingUser" onsubmit="return Validate(this);">
<fieldset>
<legend align="center">Login</legend>
<div class="a">
<div class="l">User Name</div>
<div class="r">
<INPUT type="text" name="userName">
</div>
</div>
<div class="a">
<div class="l">Password</div>
<div class="r">
<INPUT type="password" name="password">
</div>
</div>
<div class="a">
<div class="r">
<INPUT class="button" type="submit" name="submit"
value="Login">
</div>
</div>
<i align="center" style="margin-left: 183px;">New User? <a href="signup.html"><u>Signup</u></a></i>
</fieldset>
</form>
</div>
</body>
</html>
E la mia primavera-dispatcher-servlet.xml è così.
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.csc.student" />
<mvc:annotation-driven/>
<!--<bean id="HandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />-->
<!-- <bean name="/welcome.html" class ="csc.csc.helloController.HelloController" /> -->
<bean id="viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name ="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
Il mio controller è come questo.
package com.csc.student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class StudentInfoController {
@RequestMapping(value = "/indexPage.html", method = RequestMethod.GET)
public ModelAndView getAdmissionFrom() {
ModelAndView model = new ModelAndView("indexPage");
return model;
}
}
Qualcuno può aiutarmi in questo? Sto faticando molto ma non ho nessuna soluzione. Ho mantenuto il mio file js e css nella cartella WEB-INF.
Potresti spiegare il vantaggio di utilizzare questo approccio come ecc. Perché Spring ha scelto questo modo piuttosto che l'accesso tradizionale nella cartella webapps. Fornire un link anche benvenuto. –