Results 1 to 6 of 6
  1. #1
    abc21 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default text box and button click event for a web application in spring

    Hi!
    I want to create a web application in spring.
    I know that i can have code for textbox and button in html file. But how can i tie the click event of the button with the class file? the business logic should be in class file.
    For example: user can type name in a textbox and when he/she hits button, 'show' then a messagebox should appear saying- "Hi, [name typed in textbox] ".
    How can i do this?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: text box and button click event for a web application in spring

    That sounds like an Ajax call and some Javascript library for opening the box (assuming it's not simply an alert).
    That's not really Spring's field (well, the Ajax is I suppose).

  3. #3
    abc21 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: text box and button click event for a web application in spring

    as i am new to java i am thinking of developin the web app using java and html.. is it possible 2 do that? if so how can i do it?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: text box and button click event for a web application in spring

    I would suggest learning about servlets, jsps, web application servers...

  5. #5
    abc21 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: text box and button click event for a web application in spring

    i have a text and a button in my jsp file and when user clicks on button i want to display what is entered in the textbox on the same page.

    my jsp code: index.jsp

    <%@ 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>Hello</title>
    </head>
    <body>
    <form ACTION="index.jsp" METHOD="POST">

    <% java.util.Date d = new java.util.Date(); %>
    <h3>
    Today's date is <%= d.toString() %>
    </h3>

    <p> Enter name:
    <br/>
    <input type="text" id="username" name="username" />


    <input type="Submit" value="click">
    </p>

    </form>
    </body>

    </html>

    My servlet code:

    package helloWorld.servlets;

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


    /**
    * Servlet implementation class HelloWorldServlet
    */
    public class HelloWorldServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * @see HttpServlet#HttpServlet()
    */
    public HelloWorldServlet() {
    super();
    // TODO Auto-generated constructor stub
    }

    /**
    * @see Servlet#init(ServletConfig)
    */
    public void init(ServletConfig config) throws ServletException {
    // TODO Auto-generated method stub
    }

    /**
    * @see Servlet#destroy()
    */
    public void destroy() {
    // TODO Auto-generated method stub
    }

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub


    /* response.getWriter().write("Hello, world!");

    String str=hello.display();

    response.getWriter().write("\n"+str);*/

    //


    }

    /**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub

    String name= request.getParameter("username");

    response.setContentType("txt/html");
    //response.getWriter().write(name);

    PrintWriter out =response.getWriter();


    out.println("<html>");
    out.println("<head>");

    out.println("</head>");

    out.println("<body>");

    out.print("Username: ");

    if(name!=null)
    {
    out.println(name);
    }


    out.println("</body>");

    out.println("</html");

    out.flush();
    out.close();




    }

    }

    i want to print it on the same page(index.jsp). But it is not printing anything. can anyone help me with ths?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: text box and button click event for a web application in spring

    You need to forward it to the JSP, which can then read the username out of the request.
    The basic JSTL (the tag library) has tags you can use to pull that value out.

Similar Threads

  1. How to open .ods file on button click event
    By Anagha in forum New To Java
    Replies: 15
    Last Post: 07-08-2012, 09:10 PM
  2. Replies: 6
    Last Post: 03-19-2011, 03:24 AM
  3. creating a frame on button click event
    By ankit1801 in forum New To Java
    Replies: 8
    Last Post: 03-16-2011, 05:11 AM
  4. AWT - catching click button event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 11:02 PM
  5. How to perform some event to button click
    By eva in forum AWT / Swing
    Replies: 2
    Last Post: 01-16-2008, 12:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •