绝对路径的相对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
最满意答案
我厌恶命名数据帧“数据”,所以改为命名为“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 ...
-
R barplot轴缩放(R barplot axis scaling)[2023-07-13]
不确定你确切想知道的是什么,但是如果要让标签从一端到另一端均匀地(但不一定准确)运行,则: 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' ...
-
barplot - 频率应基于列中的模式和比率(x轴)(barplot - frequency should be based on a pattern in column and ratio (x axis))[2023-05-26]
我厌恶命名数据帧“数据”,所以改为命名为“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' ...
-
使用条形图分组x轴(group x axis using barplot)[2023-07-23]
如果我正确读到你,用以下标签替换你的标签: 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 ...
-
barplot x轴标签,在不同的行中具有分层分组变量(barplot x-axis labels with hierarchical grouping variables in separate rows)[2023-03-14]
稍微手动调整边距和调用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 ...