JSP and Servlet Display of text in a text field

Reply

Join Date: Feb 2007
Posts: 4
Reputation: itsnexgen is an unknown quantity at this point 
Solved Threads: 0
itsnexgen itsnexgen is offline Offline
Newbie Poster

JSP and Servlet Display of text in a text field

 
0
  #1
Feb 4th, 2007
Hello Friends,
I am trying to learn JSP, Servlets at the moment.

What am trying to do : A simple text field and a button
What should happen : When you click the button a text should appear something which is specified in the code. for example, "Pradeep".

I am really finding it difficult at the moment to actually bring the JSp and Servlet in connection.

Can anyone help me??

It would be great to start of with a problem to be solved an dthen move ahead.

Thanks and Rgds,
Pradeep (KINO)
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JSP and Servlet Display of text in a text field

 
0
  #2
Feb 4th, 2007
the button (when activated) submits a post request to the servlet, the servlet sets some information in the http requests and forwards to the JSP.

What part of that don't you get working? It's rather basic...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 4
Reputation: itsnexgen is an unknown quantity at this point 
Solved Threads: 0
itsnexgen itsnexgen is offline Offline
Newbie Poster

Re: JSP and Servlet Display of text in a text field

 
0
  #3
Feb 5th, 2007
Originally Posted by jwenting View Post
the button (when activated) submits a post request to the servlet, the servlet sets some information in the http requests and forwards to the JSP.

What part of that don't you get working? It's rather basic...
Hello Friend,

Index.jsp :

--------------------------------------------------------------
<html>
<head>
<title></title>
</head>
<body>
<h2></h2>
<form method="post" action="displayname">
<% String name="";%>
<% if(request==null){
name="";
}
else{
name=request.getParameter("name");
}
%>

Display Name:

<input type="text" name="name" value=<%=name%> />
<br>
<input type="submit" name="display" value="Display" />

</form>
</body>
</html>
-------------------------------------------------------

HelloServlet.java

-----------------------------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class HelloServlet extends HttpServlet{

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

request.setAttribute("name", "Pradeep");
getServletContext()
.getRequestDispatcher("/view.jsp").forward(request, response);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
getServletContext()
.getRequestDispatcher("/view.jsp").forward(request, response);
}
}
--------------------------------------------------------------

Any wrong in this code??

please help me try to debug.. Thanks a lot!

- KINO
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 6397 | Replies: 2
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC