【发布时间】:2014-06-24 13:47:15
【问题描述】:
假设我有一个 JSP 页面 index.jsp
<form action="https://localhost:8080/App/backend_servlet" method="get">
<ul>
<li>
<label for="name"><b>User id:</b></label>
<input type="text" name="userName" id="userName" size="40" title="Please enter Clients User id" ></input>
</li>
<li>
<label for="name"><b>Password</b></label>
<input type="text" name="pass" id="pass" title="Please enter Password."></input>
</li>
<!-- For the next input tag in the value part it should display the "String output" from the backend_Servlet-->
<li>
<label for="name"><b>Output</b></label>
<input type="text" name="output" id="output" value = "TODAY" title="it should display output as reponse"></input>
</li>
<p>
<button type="submit" class="action">Submit</button>
</p>
</form>
所以上面的 .jsp 页面包含一个向用户请求 用户名 和 密码 的表单。因此,在用户输入他的用户名和密码并单击提交页面后,将进入处理请求的 backend_servlet 必须重定向到同一页面并必须显示 字符串输出 在页面的输出字段中。
public class backend_servlet extends HttpServlet implements SingleThreadModel
{
// protected static ILogDevice m_oLogDevice;
protected void doGet( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String ls_userName = request.getParameter("userName");
String ls_pwd = request.getParameter("pass");
String output = "";
//Some Code which processes the userName and pwd and gives some value for the output string.
output = "Something";
}
}
有什么方法可以重写 index.jsp 的代码,以便它可以显示 servlet 的响应字符串。
不使用 servlet 中的 PrintWriter、response.getWriter() 并重定向回其他一些 jsp 页面。
【问题讨论】:
-
一些建议:看看Java命名约定java.about.com/od/javasyntax/a/nameconventions.htm
标签: java html css jsp servlets