箭头指向我需要输出姓氏的地方是:lion
我无法获得想要的输出。我认为问题出在index.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
}
名称controller.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);
}
}
最佳答案
更改这些行:
<tr>
<td><input name="lastName" value='${val.lastName }'/></td>
<td><input type="submit" value="Submit"></td>
</tr>
关于java - 为什么jsp中无法显示两个输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59999922/