linking jsp to servlet and that to servlet again shows some problems

一世执手 提交于 2019-12-31 05:31:09

问题


I have written a jsp code which links to a servlet and that links to a servlet again. The code, mahi1.jsp

<form action="mahi5" method="post">
<center>
    <table>
        <tr>
            <td>
                <h1><center> SIGN IN </center></h1>
    </td>
        </tr>
        <tr>
            <td>
                Email:<nbsp>   <nbsp>
            </td>
            <td>
                <input type="text" name="user" value="" size="20" />
            </td>
        </tr>          
        <tr>
            <td>Password:<nbsp>  <nbsp></td>
                    <td>
                        <input type="password" name="pass" value="" size="20" />
                    </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="submit" value="submit" />
                        </td>
                    </tr>
        </table>  

</center>
</form>

servlet-mahi5.java

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
            String emailid=request.getParameter("user");
            String password=request.getParameter("pass");
            out.println("<a href=\"a2?m="+emailid+"\">");
            out.println("Send information to someone</a>");
}

jsp-mahi6.jsp

<%
            String e1=(String)request.getParameter("emailid");
            if(e1!=null)
                               {
            %>
            <br>
            Enter the email id of the user you wanna send info to
            <input type="text" name="user1" value="" size="15"/>
            <input type="hidden" name="u1" value=<%=u1%> />
            <input type="hidden" name="e1" value=<%=e1%> />
            <input type="submit" value="proceed"/>
            <%
                              }
            %>

When i click the submit button in the first jsp page, it displays a blank page. The url says its mahi5 Could anyone help me please!


回答1:


Change the code in Servlet's service method.

PrintWriter out = response.getWriter();
String emailid=request.getParameter("user");
out.println("<a href=\"mahi6.jsp?emailid=" + emailid + "\">Send information to someone</a>");


来源:https://stackoverflow.com/questions/12018660/linking-jsp-to-servlet-and-that-to-servlet-again-shows-some-problems

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!