User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 456,484 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,835 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 3704 | Replies: 2
Reply
Join Date: Feb 2007
Posts: 4
Reputation: itsnexgen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
itsnexgen itsnexgen is offline Offline
Newbie Poster

Solution JSP and Servlet Display of text in a text field

  #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)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #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  
Join Date: Feb 2007
Posts: 4
Reputation: itsnexgen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
itsnexgen itsnexgen is offline Offline
Newbie Poster

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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 2:57 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC