Wie man Zugriff URL-Parameter in struts2
-
11-10-2019 - |
Frage
Ich arbeite an einem Projekt struts2. Ich habe url erstellt mit in meinem Projekt und haben Parameter mit Hilfe von Tags übergeben. Meine Frage ist, wie kann ich den Parameter in den Aktionen lesen? auch wenn das gleiche tun würde ich in der Lage sein, die Parameter als Query-String zu sehen. Ich frage, weil ich nicht in der Lage bin, und ich sah es in einem der Tutorials.
Lösung
Typically, you will interact with parameters in your actions by using fields on your actions, exposed by setters. Assume the following URL maps to my example Struts2 action:
URL
http://localhost/myAction?firstName=SonOfTheEARTh
Action Code
public class MyAction extends ActionSupport {
private String firstName;
public String execute() throws Exception {
// do something here
return SUCCESS;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(final String firstName) {
this.firstName = firstName;
}
}
JSP
Using Struts tags: <s:property value="firstName"/>
Using JSP EL/JSTL: ${action.firstName}
Andere Tipps
EDITED answer: It's based on naming conventions of your parameter. Take a look at this link and follow how they set "oldName" parameter.