文件上传 content-type:application/json System.Web.HttpContext.Current.Request.InputStream 读取不到数据

设置下  System.Web.HttpContext.Current.Request.InputStream.Position = 0;


        //
        // 摘要: 
        //     当在派生类中重写时,获取或设置当前流中的位置。
        //
        // 返回结果: 
        //     流中的当前位置。
        //
        // 异常: 
        //   System.IO.IOException:
        //     发生 I/O 错误。
        //
        //   System.NotSupportedException:
        //     流不支持查找。
        //
        //   System.ObjectDisposedException:
        //     在流关闭后调用方法。
        public abstract long Position { get; set; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Java中,你可以通过使用`javax.servlet.ServletContext`接口来实现类似于C#中`System.Web.HttpContext.Current.Request.MapPath()`的功能。下面是一个示例代码: ```java import javax.servlet.ServletContext; public class MapPathExample { public static String mapPath(String path) { ServletContext context = ServletContextProvider.getServletContext(); // 通过Provider获取ServletContext对象 String realPath = context.getRealPath(path); // 获取真实路径 return realPath; } } class ServletContextProvider { private static ServletContext servletContext; public static void setServletContext(ServletContext context) { servletContext = context; } public static ServletContext getServletContext() { return servletContext; } } ``` 在你的Java Web应用程序的`web.xml`文件中,你需要添加一个`ServletContextListener`来设置`ServletContext`对象。下面是一个示例`web.xml`文件的配置: ```xml <web-app> <!-- 其他配置 --> <listener> <listener-class>com.example.ServletContextListenerImpl</listener-class> </listener> </web-app> ``` 然后,你需要实现`ServletContextListener`接口,在`contextInitialized`方法中设置`ServletContext`对象。下面是一个示例`ServletContextListener`的实现: ```java import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class ServletContextListenerImpl implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext context = servletContextEvent.getServletContext(); ServletContextProvider.setServletContext(context); } @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { // 需要实现该方法,可以留空 } } ``` 现在,你可以在你的Java代码中使用`MapPathExample.mapPath(path)`方法来获取路径的真实物理路径,就像在C#中使用`System.Web.HttpContext.Current.Request.MapPath()`一样。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值