如何将表单重定向到其他页面的一部分?

时间:2019-03-21 08:56:27

标签: javascript java html jsp servlets

我的Web应用程序上有一个与我们联系的表单。我想要的是,当用户填写表格并单击“提交”按钮时,它应该重定向到其他页面的部分。

在这种情况下,应在加载ContactUsServlet.jsp页面之后显示contact99部分。以下是我的代码:-

联系我们表格:-

<form action="ContactUs" method="post">
      <p><input class="w3-input w3-border" type="text" id="name" name="name" placeholder="Name" required name="Name"></p>
      <p><input class="w3-input w3-border" type="text" id="email" name="email" placeholder="Email" required name="Email"></p>
      <p><input class="w3-input w3-border" type="text" id="subject" name="subject" placeholder="Subject" required name="Subject"></p>
      <p><input class="w3-input w3-border" type="text" id="message" name="message" placeholder="Message" required name="Message"></p>
      <p>
      </div>
        **<button class="w3-button w3-black" onclick="on()" type="submit">
          <i class="fa fa-paper-plane"></i> SEND MESSAGE
        </button>**
      </p>
    </form>
    <!-- Image of location/map -->
    <img src="/w3images/map.jpg" class="w3-image w3-greyscale" style="width:100%;margin-top:48px">
  </div>

ContactUs Servlet:-

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = request.getSession();

        PrintWriter out = response.getWriter();

        String name1=request.getParameter("name");
        String email1=request.getParameter("email");
        String subject1=request.getParameter("subject");
        String message1=request.getParameter("message");


        session.setAttribute("name01", name1);
        session.setAttribute("email01", email1);
        session.setAttribute("subject01", subject1);
        session.setAttribute("message01", name1);




   Test t=new Test(email1, "Support", "Hi "+name1+"\n \n"+"Thank you contacting us. We'll respond to your query as soon as possible"+"\n \n"+"Following is what you've written to us:- "+"\n \n"+message1);

   Test t1=new Test("emailid", "New query, query from new user "+name1+"", "Hi, A new user has sent a message."+"\n \n"+"User Email ID:- "+email1+"\n"+"User's subject:- "+subject1+"\n \n"+"User's message:- "+message1);


            try 
            {
                t.sendEmail();


              response.sendRedirect("ContactUsSuccess.jsp/#contact99");


                t1.sendEmail();
                System.out.println("Mail Sent successfully");
            } 

            catch (Exception ex) 
            {
                out.println(ex.getMessage());
            }

            }

ContactUsSuccess.jsp:-

<!-- Contact Section -->
<div id="contact99">
<div class="alert alert-success">
  <strong>Success!</strong> Message sent successfully. Please check your mail for further details
</div>
</div>

谢谢

0 个答案:

没有答案