嗨,我可以知道如何将返回值从普通的 java 类传递给 servlet,然后使用 jsp 显示它吗?我试过但只得到空值。
结果.java
package langID;
public class Result {
public String Show()
{
return "result";
}
}
Formhandler.java (servlet)
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
RequestDispatcher rd = request.getRequestDispatcher("comment.jsp");
Result demo = new Result();
String s = demo.Show();
request.setAttribute("s", s);
rd.forward(request, response);
}
评论.jsp
<%String name = (String)request.getAttribute("s"); %>
<%= s%>