944,171 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 11090
  • JSP RSS
Feb 4th, 2007
0

JSP and Servlet Display of text in a text field

Expand Post »
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)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
itsnexgen is offline Offline
4 posts
since Feb 2007
Feb 4th, 2007
0

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

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...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Feb 5th, 2007
0

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

Click to Expand / Collapse  Quote originally posted by jwenting ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
itsnexgen is offline Offline
4 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Problem adding registration data to mysql database
Next Thread in JSP Forum Timeline: Communication Link Failure Error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC