Results 1 to 6 of 6
- 02-14-2012, 06:52 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
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?
- 02-15-2012, 09:29 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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).
- 02-15-2012, 02:55 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
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?
- 02-15-2012, 03:01 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: text box and button click event for a web application in spring
I would suggest learning about servlets, jsps, web application servers...
- 02-16-2012, 05:08 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
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?
- 02-16-2012, 05:16 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
How to open .ods file on button click event
By Anagha in forum New To JavaReplies: 15Last Post: 07-08-2012, 09:10 PM -
Can we open .ods file on button click event..............
By Anagha in forum AWT / SwingReplies: 6Last Post: 03-19-2011, 03:24 AM -
creating a frame on button click event
By ankit1801 in forum New To JavaReplies: 8Last Post: 03-16-2011, 05:11 AM -
AWT - catching click button event
By Java Tip in forum Java TipReplies: 0Last Post: 03-11-2008, 11:02 PM -
How to perform some event to button click
By eva in forum AWT / SwingReplies: 2Last Post: 01-16-2008, 12:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks