使用Java检索URL中的参数 [英] Retrieving parameters in URL with Java
问题描述
我有一个使用XSL和XML生成PDF的Servlet。
由于我想通过URL指定文件,我需要从那里获取这些参数:
I have a little Servlet that uses XSL and XML to generate PDF. Since I want to specify the files via URL I need to get those Parameters from there:
localhost/Servlet?xml=c:\xml\test.xml&xsl=c:\xsl\test.xsl
所以我需要的参数是
c:\xml\test.xml
c:\xsl\test.xsl
那些需要读入变量xml-file和xsl-file。
and those need to be read into the variables xml-file and xsl-file.
我有这个,但这对我没有帮助,因为我不知道如何将值应用到变量中:
I have this but that doesn't really help me I guess since I don't know how to apply the values into the variables:
Map para = request.getParameterMap();
java.util.Iterator it = params.keySet().iterator();
while ( it.hasNext() )
{
String key = (String) it.next();
String value = ((String[]) para.get( key ))[ 0 ];
}
关于如何做到这一点的想法?
Any idea on how to do that?
谢谢,
TheVagabond
TheVagabond
推荐答案
在SERVLET中必须是request,是吗?
In SERVLET must be request, yes?
String xml_path = request.getParameter(xml);
String xml_path= request.getParameter("xml");
字符串xsl_path = request.getParameter(xsl);
String xsl_path=request.getParameter("xsl");
这篇关于使用Java检索URL中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!