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)

Recommended Answers

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...

Jump to Post

All 2 Replies

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...

[quote=jwenting;310731]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...[/quote]

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.