我正在Spring MVC框架上构建一个web应用程序,并使用thymeleaf作为我的模板引擎。
在添加新的REST控制器之前,我有一个工作应用程序。现在抛出IOException
JAVA伊奥。IOException:文件名、目录名或卷标语法不正确
java.io.IOException: The filename, directory name or volume label syntax is incorrect
at java.io.WinNTFileSystem.canonicalize0(Native Method)
at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:414)
at java.io.File.getCanonicalPath(File.java:618)
at org.eclipse.jetty.util.resource.FileResource.getAlias(FileResource.java:195)
at org.eclipse.jetty.server.handler.ContextHandler.checkAlias(ContextHandler.java:1599)
at org.eclipse.jetty.server.handler.ContextHandler.getResource(ContextHandler.java:1583)
at org.eclipse.jetty.webapp.WebAppContext.getResource(WebAppContext.java:360)
at org.mortbay.jetty.plugin.JettyWebAppContext.getResource(JettyWebAppContext.java:338)
at org.eclipse.jetty.webapp.WebAppContext$Context.getResource(WebAppContext.java:1325)
at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:153)
at org.springframework.web.servlet.resource.PathResourceResolver.isResourceUnderLocation(PathResourceResolver.java:177)
at org.springframework.web.servlet.resource.PathResourceResolver.checkResource(PathResourceResolver.java:148)
at org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:121)
at org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:92)
at org.springframework.web.servlet.resource.PathResourceResolver.resolveResourceInternal(PathResourceResolver.java:76)
at org.springframework.web.servlet.resource.AbstractResourceResolver.resolveResource(AbstractResourceResolver.java:46)
at org.springframework.web.servlet.resource.DefaultResourceResolverChain.resolveResource(DefaultResourceResolverChain.java:57)
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.getResource(ResourceHttpRequestHandler.java:271)
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:208)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:745)
只有当浏览器试图从我的taoC获取css、js或任何其他静态资源时才会发生这种情况onnection-servlet.xml.我的jetty和tomcat7部署都发生了同样的事情。经过几个小时的搜索,我找不到任何类似的问题。
编辑:我正在调用/account请求映射,但它适用于所有访问静态资源的请求映射。如果我试图直接在浏览器中访问资源,例如。http://localhost:8080/css/bootstrap.min.css或http://localhost:8080/js/sb-管理员2。js异常被抛出。
或者,如果我试图访问假资源,例如。http://localhost:8080/js/fake.js我仍然得到了一个标准的http 404,这是预期的,但没有抛出IOException。
项目结构
-src -main -java -*controller -MainController.java -RestAccountController.java -resources -META-INF -spring -applicationContext.xml -webapp -css -font-awesome-4.1.0 -js -less -pages -WEB-INF -taoConnection-servlet.xml -web.xml
TAOConnection-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
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">
<import resource="classpath*:META-INF/spring/applicationContext*.xml" />
<context:component-scan base-package="com.quadrimular.nts.results.connection.*" />
<context:component-scan base-package="com.quadrimular.nts.results.connection" />
<mvc:annotation-driven/>
<mvc:resources mapping="/css/**" location="/css/**" />
<mvc:resources mapping="/js/**" location="/js/**" />
<mvc:resources mapping="/font-awesome-4.1.0/**" location="/font-awesome-4.1.0/**" />
<mvc:resources mapping="/pages/**" location="/pages/**" />
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/pages/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="false" />
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="order" value="1" />
</bean>
<!-- Configure to plugin JSON as request and response in method handler -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonMessageConverter"/>
</list>
</property>
</bean>
<!-- Configure bean to convert JSON to POJO and vice versa -->
<bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
</beans>
主ontroller.java
package com.quadrimular.nts.results.connection.controller;
import org.springframework.beans.factory.annotation.Autowired;
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 com.quadrimular.fyfe.fulfillment.service.AccountService;
@Controller
public class MainController {
@Autowired
private AccountService accountService;
@RequestMapping(value = "/account", method = RequestMethod.GET)
public String getAllaccounts(ModelMap model){
try{
model.addAttribute("accountList", accountService.getAllAccounts());
}catch(Exception e){
model.addAttribute("error", true);
model.addAttribute("errMsg", e.getMessage());
}
return "account";
}
@RequestMapping(value = "/main", method = RequestMethod.GET)
public String main(ModelMap model){
return "main";
}
@RequestMapping(value = "/account", method = RequestMethod.PUT)
public String addAccount(ModelMap model){
return "account";
}
}
重新记帐控制器。JAVA
package com.quadrimular.nts.results.connection.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import com.quadrimular.fyfe.fulfillment.Account;
import com.quadrimular.fyfe.fulfillment.service.AccountService;
@RestController
@RequestMapping(value = "/api")
public class RestAccountController {
AccountService accountService;
@Autowired
public RestAccountController(AccountService accountService){
this.accountService = accountService;
}
@RequestMapping(value="/account", method= RequestMethod.GET, headers = "Accept=application/json")
public List<Account> getAllAccounts(){
List<Account> accounts = accountService.getAllAccounts();
return accounts;
}
@RequestMapping(value="/account", method=RequestMethod.POST, headers = "Accept=application/json")
public Account addAccount(@RequestBody Account act) throws Exception{
return accountService.addAccount(act);
}
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public String handleException(Exception e) {
return "Error: " + e.getMessage();
}
}
网状物xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>taoConnection</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>taoConnection</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
试试这个:
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/font-awesome-4.1.0/**" location="/font-awesome-4.1.0/" />
<mvc:resources mapping="/pages/**" location="/pages/" />
我有一个log4j2。我用来定义输出到的一些记录器的xml文件。日志文件。 在. xml已经读入之后,我在java中为logger fileNames设置了完整路径。 代码按预期工作,日志被输出到更新的路径,但我遇到以下错误: 2022-01-18 15:05:26685主要错误文件管理器(${sys:logFileName})java。伊奥。IOException:文件名、目录名或卷标语法不正确
我知道这可能很简单,但我解决不了。 我试图将一个文件从Java客户端上传到webdav服务器,这是我的代码片段 在创建o/p流时,我得到 JAVA伊奥。FileNotFoundException:https:\webdavserverurl\Uploads\abc。csv(文件名、目录名或卷标语法不正确) 为什么它会改变路径?我该如何修复它? 注: 这是一个请求。文件abc.csv正在服务器位置创
问题内容: 我正在尝试使用以下代码复制文件: 对于某些用户,此异常的结果是: 文件名和目录名似乎正确。甚至在执行复制代码之前检查目录是否存在,文件名看起来像这样: 用户具有的写入权限,并且可以使用OS毫无问题地复制文件。 由于我无法访问计算机,因此这种情况仍在发生,并且无法在我自己的计算机上重现该问题,因此我向您寻求有关此异常原因的提示。 问题答案: 尝试此操作,因为它更需要调整targetPat
最近刚刚退出expo,我正试图在android设备上运行我的应用程序。我按照说明进行了操作(可能是正确的),但是当我尝试运行我的应用程序时,我总是收到这个错误: 使用'- warning-mode all '来显示各个弃用警告。见https://docs . grad le . org/6 . 0 . 1/user guide/command _ line _ interface . html #
警告:JKS密钥存储库使用专有格式。建议使用“keytool-importkeystore-srckeystore c:\users\hp.android\debug.keystore-destkeystore c:\users\hp.android\debug.keystore-deststoretype PKCS12”迁移到PKCS12,这是一种行业标准格式。 当我要迁移到PKCS12时,就会
我想解码我从画廊拍的照片,但它有一个错误。我尝试过各种方法,但都没有成功。请帮我修改代码。 这是我的代码:https://pastebin.com/syWjqPDK } 这是logcat的结果