linking jsp to servlet and that to servlet again s

2020-05-08 06:20发布

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!

标签: jsp servlets
1条回答
▲ chillily
2楼-- · 2020-05-08 07:10

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>");
查看更多
登录 后发表回答