Стрелка там, где она указана, мне нужна выходная фамилия: лев
Я не могу получить желаемый результат. Я думаю, что проблема в индексе. jsp или NameController. java файл
Индекс jsp код
<form name="greetingForm" action="NameController" method="post" style="width: 300px; ">
<table>
<tr>
<td>Please enter your name</td>
</tr>
<tr>
<td><input name="name" value='${nameForm.name}'/></td>
</tr>
<tr>
<td>Enter Last name</td>
</tr>
<tr>
<td><input name="lastName" value='${nameForm.lastName }'/></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
<input id="greetingField" value='${nameForm.greetingText}' style ="background-color: white; border: none; width: 400px;" disabled="disabled" />
<input id="greetingFields" value='${val.idText }' style ="background-color: white; border: none; width: 400px;"disabled = "disabled" />
<input id="currentTime" value='${nameForm.currentTime}' style ="background-color: white; border: none; width: 400px;" disabled="disabled" />
</table>
</body>
</html>
NameForm . java
public void setCurrentTime(String currentTime) {
this.currentTime = currentTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
//my code
public String getlastName() {
return lastName;
}
public void setlastName(String lastName) {
this.lastName = lastName;
}
//my code ends
public String getGreetingText() {
return greetingText;
}
public void setGreetingText(String greetingText) {
this.greetingText = greetingText;
}
//my code
public String getIdText() {
return idText;
}
public void setIdText(String idText) {
this.idText = idText;
}
//my code ends
}
Имя контроллера. java
public class NameController extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
NameForm nameForm = new NameForm();
NameForm val = new NameForm();
nameForm.setName(request.getParameter("name"));
val.setlastName(request.getParameter("lastName"));
session.setAttribute("nameForm",nameForm);
session.setAttribute("val", val);
nameForm.setGreetingText("Hello "+nameForm.getName());
val.setGreetingText("last name is:" +val.getlastName());
getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
}
}