Multiple Http Servlets string path mapping [duplicate] - java

This question already has answers here:
Servlet and path parameters like /xyz/{value}/test, how to map in web.xml?
(7 answers)
Closed 6 years ago.
I'm want to map these two different servlets (using addServletWithMapping):
"/soccerapp/teams/*"
"/soccerapp/teams/*/players
but the second is obviously never reached, is any other special char that I can use in the string path to solve the problem?

The wildcard in the middle of the path is not evaluated. You can see this answer https://stackoverflow.com/a/15386616/1630604 for a complete description how the path are evaluated.
Anyway, you cannot map two Servlet to one URL.

Related

Best way to get a sub-path of a file [duplicate]

This question already has answers here:
How to construct a relative path in Java from two absolute paths (or URLs)?
(23 answers)
Closed 6 years ago.
I have two File objects:
C:/basepath/
C:/basepath/directory/file.txt
Now I would like to subtract file 1 from file 2 so that I get directory/file.txt.
I don't want to use String.substring() since file paths may differ from input.
Use the features of java.nio.file.Path. You are looking to 'relativize'.

A step back in a path hierarchy [duplicate]

This question already has answers here:
How to get just the parent directory name of a specific file
(10 answers)
Closed 7 years ago.
I have a path to a folder and want to change it. But first I want to get a step back.
String path = "C:\Users\Jurgen\Java\Project\Folder\inner_folder\";
How do I get a step back in a path hierarchy?
For example:
String path = "C:\Users\Jurgen\Java\Project\Folder\";
Extract a substring up until the last slash
String newPath = path.substring(0, path.lastIndexOf('\'));
Edit: (because I'm being challenged on this answer)
Some people will tell you that treating paths as strings is wrong, in this case it doesn't make a difference. The other option of creating a Path object then using it's .getParent() method or prior to Java 7, a File object.
Convert it to a Path with Paths.get(path); and use its getParent() method.

I need to send an arbitrary text string using java.awt.Robot.send() [duplicate]

This question already has answers here:
Convert String to KeyEvents
(16 answers)
Closed 7 years ago.
I need a way to do what is described in the first answer to this question: Type a String using java.awt.Robot
Only I would like to avoid using the clipboard. Is there a generic way to do it without?
(Other answers to the question address printing some hard-coded keys, but they don't help me print "Hello, world!")
You can use javax.swing.KeyStroke to transform the characters in your string into keycodes. For each key code, call Robot.keyPress(...), Robot.keyRelease(...) as you are doing in your previous question

Getting parameter from forward [duplicate]

This question already has answers here:
What is the difference between == and equals() in Java?
(26 answers)
Closed 8 years ago.
I'm working on a project and I have a problem. I send a parameter from a jsp page via forward to another jsp page and although it has the value that I declared (I printed it and it works), when I use it in an if clause the code doesn't work. Here is the part of the code:
String parameter = request.getParameter("loginparam"); //loginparam is the the name of parameter in the forward statement whick has value "now"
if(parameter == "now"){
prints the jsp page
}else{
response.sendRedirect("mainpage.jsp");
}
It always redirects me in mainpage although when I print parameter it has the "now" value.
Try with,
if(parameter.equals("now")){
And Read

java calculate pathname difference [duplicate]

This question already has answers here:
How to construct a relative path in Java from two absolute paths (or URLs)?
(23 answers)
Closed 6 years ago.
Is there an open source library that, given ...
/a/b/c
/a/b/c/d/e
would return ../..
or for that matter given
/a/b/c/d
/a/b/c/e
would return ../d
?
If you don't mind passing by converting your Strings into URI then this latter one has the method relativize which should do exactly what you want, take a look here.

Categories

Resources