Retrieving parameters in URL with Java
Solution 1
In SERVLET must be request, yes?
String xml_path= request.getParameter("xml");
String xsl_path=request.getParameter("xsl");
Solution 2
I think you simply want request.getParameter(String param)
e.g.
String xml = request.getParameter("xml");
Note (for future reference) that the above won't handle multiple xml
parameters. For that you should use request.getParameterValues(String param)
As noted above you probably shouldn't be passing filenames around. In preference I would upload the file, generate the PDF and make that available (simply via the response, or perhaps store it local to your servlet deployment and return an id for later retrieval?)
Solution 3
What's wrong with this?
String xsl = request.getParameter("xsl");
String xml = request.getParameter("xml");
Solution 4
You can just get parameters by name with HttpServletRequest.getParameter()
...
String xml-file = request.getParameter("xml");
String xsl-file = request.getParameter("xsl");
Thevagabond
Trying to get different languages to work and always improve my skills.
Updated on July 09, 2022Comments
-
Thevagabond almost 2 years
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
so the parameters that I need are
c:\xml\test.xml c:\xsl\test.xsl
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?
Thanks,
TheVagabond
-
Thevagabond over 11 yearsThere is only one xml and one xsl Parameter