首页 \ 问答 \ 绝对路径的相对URL(Relative URL to Absolute Path)

绝对路径的相对URL(Relative URL to Absolute Path)

我想要做的是阅读html文件的内容。 点击一个链接,应该读取html文件内容,并在我的代码中使用该内容。

我尝试了什么:

我尝试将相对路径转换为绝对路径

String absoluteFilePath = servletContext.getRealPath("/html/en/TestPage.html");

这在我的Windows开发机器上的weblogic中运行良好但是当这个代码在Unix机器上部署到webloic时,上面的代码返回null。 我挖了谷歌,我找到了

“如果servlet容器由于任何原因(例如,当从.war存档中提供内容时)无法将虚拟路径转换为实际路径,则servletContext.getRealPath将返回null。”

能否请您建议将相对路径转换为绝对路径的最佳方法(使用上下文路径)。 代码应该在Windows以及Unix平台上工作,或者以其他方式读取html文件,而不是从绝对路径读取,如果我可以从相对路径读取文件文件。


what I am trying to do is to read content of html file. On click of a link the html file content should be read and that content will be used somwhere in my code.

What I tried:

I tried converting relative path to absolute path

String absoluteFilePath = servletContext.getRealPath("/html/en/TestPage.html");

and this works fine in weblogic on my windows dev machine but when this code is deployed to webloic on Unix machine the above code is returning null. I dig up google and I found

"servletContext.getRealPath returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive)."

Can you please suggest best way to convert the relative path to absolute(using context path). The code should work on windows as well as on Unix platform or some other way round to read the html file like instead of reading from absolute path if I can read file file from relative path.


原文:https://stackoverflow.com/questions/26273868
更新时间:2024-03-30 07:03

最满意答案

我厌恶命名数据帧“数据”,所以改为命名为“pdat”:

 barplot( table(pdat[ grep("R[A-Z]{2}S", pdat$Amino.acid), "log2.ratio"] ))

这与我可以通过这个小数据集得到的具体情况一样。 grepping模式不会注册“AARP; SNORE”:

> grep("R[A-Z]{2}S","AARP;SNORE")
integer(0)

这是互补行的图(仅作为减号):

barplot( table(pdat[ -grep("R[A-Z]{2}S", pdat$Amino.acid), "log2.ratio"] ))

它不是密度,因此达到hte密度函数会使你的努力失败。


I have an aversion to naming dataframes "data" so instead named it "pdat":

 barplot( table(pdat[ grep("R[A-Z]{2}S", pdat$Amino.acid), "log2.ratio"] ))

That's about as specific as I can get with that tiny dataset. The grepping pattern would not register with "AARP;SNORE":

> grep("R[A-Z]{2}S","AARP;SNORE")
integer(0)

This is the plot for the complementary rows (just as a minus sign):

barplot( table(pdat[ -grep("R[A-Z]{2}S", pdat$Amino.acid), "log2.ratio"] ))

It's not a density, so reaching for hte density function will doom your efforts.

相关问答

更多
  • @ Pascal的评论链接到两个可能的解决方案,但最重要的是你需要手动添加汽车名称。 要知道要使用哪些汽车名称需要第一步:如果你看一下mtcars ,你会发现它们没有出现在列标题下,这意味着它们是行名。 为了得到他们,简单地说: carnames <- rownames(fourcyl)[ order(fourcyl$mpg, decreasing=TRUE) ] 从这里,您需要知道如何以及在何处添加它们。 也许许多人看到的第一个地方是axis ,你可以做以下事情: axis(side=1, at=1:l ...
  • 不确定你确切想知道的是什么,但是如果要让标签从一端到另一端均匀地(但不一定准确)运行,则: x = c(1:81) bp <- barplot(x) axis(side=1,at=bp[1+c(0,20,40,60,80)],labels=c(20,40,60,80,100)) 对我来说难题就是为什么你想把“20”标记为0.但这是一种方法。 Not sure exactly what you wnat, but If it is to have the labels running from one en ...
  • 根据戴维斯的回应编辑: 这是一种黑客的方式。 我猜想有一个更简单的方法。 但是您可以通过从barplot保存酒吧的位置并进行上下调整,来抑制标签的标签和barplot 。 这是mtcars数据集的一个例子: x <- barplot(table(mtcars$cyl), xaxt="n") labs <- paste(names(table(mtcars$cyl)), "cylinders") text(cex=1, x=x-.25, y=-1.25, labs, xpd=TRUE, srt=45) ED ...
  • 如果将参数names.arg提供给names.arg ,则不需要axis标记barplot : barplot(data[1,], horiz = T, las=1, xlim = c(-0.04,0.04), xaxt='n', ylab='', beside=T, col=c('springgreen'), names.arg=c(expression(xi),expression(rho), expression(alpha), expression(bar(V)))) There' ...
  • 我厌恶命名数据帧“数据”,所以改为命名为“pdat”: barplot( table(pdat[ grep("R[A-Z]{2}S", pdat$Amino.acid), "log2.ratio"] )) 这与我可以通过这个小数据集得到的具体情况一样。 grepping模式不会注册“AARP; SNORE”: > grep("R[A-Z]{2}S","AARP;SNORE") integer(0) 这是互补行的图(仅作为减号): barplot( table(pdat[ -grep("R[A-Z]{2 ...
  • sns.barplot()将返回绘图的轴。 您可以使用它来设置刻度标签: import matplotlib.pyplot as plt import pandas as pd import seaborn as sns color = ['r', 'g', 'b'] train_df = pd.read_csv("unclean_text.csv", sep='\t') label_text = pd.read_csv("labels.csv") is_dup = train_df['category' ...
  • 如果我正确读到你,用以下标签替换你的标签: label = rep(column,each=6) 应该提供所需的结果。 编辑; 如果每组只需要一个标签 label = as.vector(rbind("",paste("S",1:5,sep=""),"")) If i read you correctly, replacing your label with: label = rep(column,each=6) Should provide the desired result. Edit; If ...
  • 我会改变两件事: df$ordersample <- factor(df$Sample., levels = sort(unique(df$Sample.))) 和 + facet_grid(.~orderweeks, scales = 'free_x') I would change two things: df$ordersample <- factor(df$Sample., levels = sort(unique(df$Sample.))) and + facet_grid(.~order ...
  • 您可以通过在正确的位置命名“分数”来实现 scores <- sample(1000) names(scores)<-NA names(scores)[seq(1, 1000, 111)]<-1:10 barplot(scores, main="my plot", xlab="my 1000 scores") 这个怎么用? 我们将分解这一行: names(scores)[seq(1, 1000, 111)] <- 1:10 我们已经为“得分”(NA)中的每个值指定了一个名称 我可以用names(scor ...
  • 稍微手动调整边距和调用axis()两次就可以实现。 保存像bp <- barplot(...)这样的条形图可以保存每个条形的中点以供将来参考。 oldpar <-par(mar=c(7,5.1,4.1,2.1)) bp <- barplot(a, col=c("blue","red","purple"), ylab="Frequency of Interpretation", xlab="", main="Frequency of BrP a ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。