我意识到之前已经问过这个问题。但我已经尝试了所有建议的解决方案,它仍然无法正常工作。我本身并没有收到任何错误。不是我能看到的。但我的css装载也不是。以下是相关信息:
SpringWebAppInitializer.java
public class SpringWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(ApplicationContextConfig.class);
context.setServletContext(container);
ServletRegistration.Dynamic dispatcher = container.addServlet("SpringDispatcher", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}}
ApplicationContextConfig
@EnableWebMvc
@Configuration
@ComponentScan(basePackages ="com.lisawestberg.noxml.controller")
@EnableTransactionManagement
public class ApplicationContextConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
@Bean(name = "viewResolver")
public InternalResourceViewResolver getViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/pages/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
@Bean(name = "dataSource")
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
dataSource.setUrl("jdbc:derby://localhost:1527/School");
dataSource.setUsername("root");
dataSource.setPassword("rootroot");
return dataSource;
}
private Properties getHibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.show_sql", "true");
return properties;
}
@Autowired
@Bean(name = "sessionFactory")
public SessionFactory getSessionFactory(DataSource dataSource) {
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
sessionBuilder.addProperties(getHibernateProperties());
sessionBuilder
.addAnnotatedClasses(Course.class);
return sessionBuilder.buildSessionFactory();
}
@Autowired
@Bean(name = "transactionManager")
public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
return transactionManager;
}
@Autowired
@Bean(name = "CourseDao")
public CourseDAO getCourseDao(SessionFactory sessionFactory) {
return new CourseDaoImpl(sessionFactory);
}}
CourseController
@Controller
public class CourseController {
@Autowired
private CourseDAO dao;
@RequestMapping("/")
public ModelAndView handleRequest() throws Exception {
List<Course> listCourses = dao.list();
ModelAndView model = new ModelAndView("course");
model.addObject("course", listCourses);
return model;
}
@RequestMapping(value = "/new", method = RequestMethod.GET)
public ModelAndView newCourse() {
ModelAndView model = new ModelAndView("CourseForm");
model.addObject("course", new Course());
return model;
}
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public ModelAndView editCourse(HttpServletRequest request) {
int courseId = Integer.parseInt(request.getParameter("id"));
Course course = dao.get(courseId);
ModelAndView model = new ModelAndView("CourseForm");
model.addObject("course", course);
return model;
}
@RequestMapping(value = "/delete", method = RequestMethod.GET)
public ModelAndView deleteCourse(HttpServletRequest request) {
int courseId = Integer.parseInt(request.getParameter("id"));
dao.delete(courseId);
return new ModelAndView("redirect:/");
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelAndView saveCourse(@ModelAttribute Course course) {
dao.saveOrUpdate(course);
return new ModelAndView("redirect:/");
}}
course.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Courses</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link type="text/css" href="/resources/css/myCss.css" rel="stylesheet"/>
</head>
<body>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Courses</h3>
</div>
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th style="width: 95%"></th>
<th style="width: 5%"></th>
</tr>
</thead>
<tbody>
<c:forEach var="course" items="${course}" >
<tr>
<td>
<form method="POST" action="./grades.jsp"><span name="courseid" value="<c:out value="${course.id}"/>" />
<input type="submit" class="submitLink" value="<c:out value="${course.name}" />" />
</form>
</td>
<td>
<form method="GET" action="./delete" />
<span name="id" value="<c:out value="${course.id}" />" />
<input type="image" name="submit" src="/resources/images/delete.png" border="0" alt="Submit" />
</form>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-2"></div>
</div>
</body>
</html>
文件位置
JSP:C:\ Users \ liwe \ Documents \ NetBeansProjects \ noxml \ src \ main \ webapp \ WEB-INF \ pages
CSS:C:\ Users \ liwe \ Documents \ NetBeansProjects \ noxml \ src \ main \ webapp \ resources \ css
Glassfish服务器日志
Launching GlassFish on Felix platform
May 15, 2016 2:41:04 PM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner createBundleProvisioner
INFO: Create bundle provisioner class = class com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner.
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishRuntime@3108b784 in service registry.
Cannot find the resource bundle for the name com.sun.logging.enterprise.system.container.ejb for class org.glassfish.kernel.javaee.MEJBService using org.glassfish.main.core.javaee-kernel [134]
#!## LogManagerService.postConstruct : rootFolder=C:\Program Files\payara41\glassfish
#!## LogManagerService.postConstruct : templateDir=C:\Program Files\payara41\glassfish\lib\templates
#!## LogManagerService.postConstruct : src=C:\Program Files\payara41\glassfish\lib\templates\logging.properties
#!## LogManagerService.postConstruct : dest=C:\Program Files\payara41\glassfish\domains\domain1\config\logging.properties
Info: Running Payara Version: Payara Server 4.1.1.161.1 #badassfish (build 63)
Info: Server log file is using Formatter class: com.sun.enterprise.server.logging.ODLLogFormatter
Info: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
Info: Registered fish.payara.ha.hazelcast.store.HazelcastBackingStoreFactoryProxy for persistence-type = hazelcast in BackingStoreFactoryRegistry
Info: Registered Hazelcast BackingStoreFactory with persistence-type = hazelcast
Info: Authorization Service has successfully initialized.
Info: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Info: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Info: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
Info: Grizzly Framework 2.3.23 started in: 162ms - bound to [/0.0.0.0:9090]
Info: Grizzly Framework 2.3.23 started in: 24ms - bound to [/0.0.0.0:8181]
Info: Grizzly Framework 2.3.23 started in: 10ms - bound to [/0.0.0.0:4848]
Info: Grizzly Framework 2.3.23 started in: 2ms - bound to [/0.0.0.0:3700]
Info: Java security manager is disabled.
Info: Entering Security Startup Service.
Info: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
Info: Security Service(s) started successfully.
Info: Created HTTP listener http-listener-1 on host/port 0.0.0.0:9090
Info: Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181
Info: Created HTTP listener admin-listener on host/port 0.0.0.0:4848
Info: Created virtual server server
Info: Created virtual server __asadmin
Info: Setting JAAS app name glassfish-web
Info: Virtual server server loaded default web module
Info: WebModule[null] ServletContext.log():1 Spring WebApplicationInitializers detected on classpath
Info: Initializing Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) for context '/noxml'
Info: HV000001: Hibernate Validator 5.1.2.Final
Info: WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'SpringDispatcher'
Info: FrameworkServlet 'SpringDispatcher': initialization started
Info: Refreshing WebApplicationContext for namespace 'SpringDispatcher-servlet': startup date [Sun May 15 14:41:14 CEST 2016]; root of context hierarchy
Info: Registering annotated classes: [class com.lisawestberg.noxml.config.ApplicationContextConfig]
Info: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
Info: Loaded JDBC driver: org.apache.derby.jdbc.ClientDriver
Info: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Info: HHH000412: Hibernate Core {4.3.11.Final}
Info: HHH000206: hibernate.properties not found
Info: HHH000021: Bytecode provider name : javassist
Info: HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
Info: HHH000399: Using default transaction strategy (direct JDBC transactions)
Info: HHH000397: Using ASTQueryTranslatorFactory
Info: Mapped "{[/]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.handleRequest() throws java.lang.Exception
Info: Mapped "{[/save],methods=[POST]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.saveCourse(com.lisawestberg.noxml.entity.Course)
Info: Mapped "{[/new],methods=[GET]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.newCourse()
Info: Mapped "{[/edit],methods=[GET]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.editCourse(javax.servlet.http.HttpServletRequest)
Info: Mapped "{[/delete],methods=[GET]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.deleteCourse(javax.servlet.http.HttpServletRequest)
Info: Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
Info: Looking for @ControllerAdvice: WebApplicationContext for namespace 'SpringDispatcher-servlet': startup date [Sun May 15 14:41:14 CEST 2016]; root of context hierarchy
Info: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@63136c5b] of Hibernate SessionFactory for HibernateTransactionManager
Info: FrameworkServlet 'SpringDispatcher': initialization completed in 6789 ms
Info: Loading application [noxml] at [/noxml]
Info: Loading application noxml done in 14,361 ms
Info: Payara Server 4.1.1.161.1 #badassfish (63) startup time : Felix (2,677ms), startup services(15,350ms), total(18,027ms)
Info: Cleaning JarFileFactory Cache to prevent jar FD leaks
Info: Grizzly Framework 2.3.23 started in: 30ms - bound to [/0.0.0.0:7676]
Info: JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://DESKTOP-UTDNPN2.lan:8686/jndi/rmi://DESKTOP-UTDNPN2.lan:8686/jmxrmi
Info: Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181
Info: Grizzly Framework 2.3.23 started in: 4ms - bound to [/0.0.0.0:8181]
Info: Created HTTP listener http-listener-1 on host/port 0.0.0.0:9090
Info: Grizzly Framework 2.3.23 started in: 15ms - bound to [/0.0.0.0:9090]
Info: WebModule[null] ServletContext.log():Destroying Spring FrameworkServlet 'SpringDispatcher'
Info: Closing WebApplicationContext for namespace 'SpringDispatcher-servlet': startup date [Sun May 15 14:41:14 CEST 2016]; root of context hierarchy
Severe: Cannot find the resource bundle for the name com.sun.logging.enterprise.system.core for class com.sun.ejb.containers.interceptors.JavaEEInterceptorBuilderImpl using org.glassfish.main.ejb.ejb-container [73]
Severe: Cannot find the resource bundle for the name com.sun.logging.enterprise.resource.corba for class org.glassfish.enterprise.iiop.impl.GlassFishORBManager using org.glassfish.main.orb.iiop [222]
Info: Listening to REST requests at context: /management/domain.
Info: Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@7c1812b3 as OSGi service registration: org.apache.felix.framework.ServiceRegistrationImpl@4e31c3ec.
Info: WebModule[null] ServletContext.log():1 Spring WebApplicationInitializers detected on classpath
Info: Initializing Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) for context '/noxml'
Info: Initializing Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) for context ''
Info: WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'SpringDispatcher'
Info: FrameworkServlet 'SpringDispatcher': initialization started
Info: Refreshing WebApplicationContext for namespace 'SpringDispatcher-servlet': startup date [Sun May 15 14:41:29 CEST 2016]; root of context hierarchy
Info: Loading application [__admingui] at [/]
Info: Loading application __admingui done in 2,567 ms
Info: Registering annotated classes: [class com.lisawestberg.noxml.config.ApplicationContextConfig]
Info: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
Info: Loaded JDBC driver: org.apache.derby.jdbc.ClientDriver
Info: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Info: HHH000412: Hibernate Core {4.3.11.Final}
Info: HHH000206: hibernate.properties not found
Info: HHH000021: Bytecode provider name : javassist
Info: HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
Info: HHH000399: Using default transaction strategy (direct JDBC transactions)
Info: HHH000397: Using ASTQueryTranslatorFactory
Info: Mapped "{[/]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.handleRequest() throws java.lang.Exception
Info: Mapped "{[/save],methods=[POST]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.saveCourse(com.lisawestberg.noxml.entity.Course)
Info: Mapped "{[/new],methods=[GET]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.newCourse()
Info: Mapped "{[/edit],methods=[GET]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.editCourse(javax.servlet.http.HttpServletRequest)
Info: Mapped "{[/delete],methods=[GET]}" onto public org.springframework.web.servlet.ModelAndView com.lisawestberg.noxml.controller.CourseController.deleteCourse(javax.servlet.http.HttpServletRequest)
Info: Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
Info: Looking for @ControllerAdvice: WebApplicationContext for namespace 'SpringDispatcher-servlet': startup date [Sun May 15 14:41:29 CEST 2016]; root of context hierarchy
Info: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@12e15b8a] of Hibernate SessionFactory for HibernateTransactionManager
Info: FrameworkServlet 'SpringDispatcher': initialization completed in 4320 ms
Info: Loading application [noxml] at [/noxml]
Info: noxml was successfully deployed in 8,755 milliseconds.
Info: Hibernate: select this_.ID as ID1_0_0_, this_.NAME as NAME2_0_0_ from COURSE this_
Info: Hibernate: select this_.ID as ID1_0_0_, this_.NAME as NAME2_0_0_ from COURSE this_