Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:30:51+00:00 2026-06-07T03:30:51+00:00

i want to add a button when i click it the date should be

  • 0

i want to add a button when i click it the date should be displayed but the button doesn’t work .

my servlet:

package test.servlets; 

  import java.io.*;
  import javax.servlet.*;


      public class FunctionalTestServlet extends HttpServlet
        {

public void doGet(HttpServletRequest request,HttpServletResponse response)throws    

        ServletException, IOException {



     response.setContentType("text/html");
      PrintWriter out = response.getWriter();  
      String text = request.getParameter("montext");
      String fileName = request.getParameter("testclass");

      out.println("<b><font color='blue'>The text is :</font></b>" 
      + "<b>"+ text +"</b>" + "<br>");

      out.println("<b><font color='blue'>The File name is :</font></b>" 
              + "<b>"+ fileName+"</b>" + "<br>");


      out.println("<% public void executeTest() {" +

 " java.util.Date d = new java.util.Date();out.println(d.toString()); } %>");
 **out.println("<input type='submit' value='Execute Test'onclick='executeTest()'>");**

    }


}

jsp page :

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   

"http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
   </head>
      <body>

    <html:file properties="tonFichier" name="tonForm"/>

    <form action="FunctionalTestServlet" enctype="multipart/form-data" method="get">
    <p>
  Type some text (if you like):<br>
  <input type="text" name="montext" size="30">
   </p>
    <p>
    Please specify a Test , or a set of tests:<br>
   <input type="file" name="testclass" size="40" >
    </p>
   <div>
  <input type="submit" value="Execute Test">

     </div>
   </form>
   </body>
  </html>

Any idea please
Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:30:54+00:00Added an answer on June 7, 2026 at 3:30 am

    This is certainly wrong:

    out.println("<% public void executeTest() {" +
    

    You cannot generate scriptlet code in servlet. Scriptlet code belongs to JSP. Any text returned from JSP (sent to out) is sent directly to the client. Thus the HTML delivered to the browser will contain scriptlet code – which should have been evaluated on the server-side!

    Scriptlets can only appear in JSP.

    To make it even funnier, you are trying to attach Java executeTest() method as a JavaScript onclick handler – will never work:

    out.println("<input type='submit' value='Execute Test'onclick='executeTest()'>")
    

    In fact your code is broken is so many ways that it requires complete rethink/rewrite. Start from understanding how, when and where servlets, JSP and JavaScript works.

    I kind of get your idea and guess what, it doesn’t require neither JSP nor servlets. Just write onlick handler in JavaScript and modify the DOM somehow to print current date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a ZedGraph when I click a button, but the ZedGraph
I want to add a UIViewController on my current UIView on a button click
I want to add a click able button to a MKAnnotation as seen in
I want to add a debounce to a button, but i want to perform
i want to add Layout Dynamically on Add button click and on Dynamic Layout
I want to open a date picker by clicking on button. But when I
I'm making my own minor mode for emacs. Now I want to add button
I want to add a button to JTabbedPane's title bar (similar to the 'open
I want to add Excel button below the html table, that gives an Excel
I want to add a button to each row of a column of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.