Results 1 to 3 of 3
  1. #1
    Unni is offline Member
    Join Date
    Jul 2007
    Posts
    6
    Rep Power
    0

    Default Blank result for jsp_servlet in Eclipse

    Hello all,

    Greetings!!!

    I am new to this forum and also to Eclipse..

    Have created index.jsp under WebContent in Eclipse. Having firstname and surname text boxes with submit button. Contents look like :

    Java Code:
    <form action="GreetingServlet" method="POST">
            First Name: <input type="text" name="firstName" size="20"><br>
            Surname: <input type="text" name="surname" size="20">
            <br><br>
            <input type="submit" value="Submit">
    and created GreetingServlet by right clicking ProjectName(HelloServlets) -> New -> Projects -> Servlet
    Contents look like:

    Java Code:
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            String firstName = request.getParameter("firstName").toString();
            String surname = request.getParameter("surname").toString();
    
        	}
    The problem is that, variables out,firstName,surname are underlined with yellow line in Eclipse's default browser . and when i keep the cursor on that variables then it displays warning message like "The local variable is never read".

    SO i guess no contact between jsp and servlet files.. but when i submit the page is directing to http://localhost:8080/HelloServlets/GreetingServlet

    but its blank .. Pls Help to execute this program correctly in Eclipse

    Thanks in advance

    Regards
    Unni
    Last edited by JavaBean; 07-06-2007 at 08:21 PM. Reason: Codes should be put inside [code] tags!

  2. #2
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default

    The warning appears because you don't write the lines to print the first name and surname.

    Java Code:
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		
    		response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            
            out.println("<title>Example</title>" +
            "<body bgcolor=FFFFFF>");
    
            out.println("<h2>Button Clicked</h2>");
         
            String firstName = request.getParameter("firstName").toString();
            String surname = request.getParameter("surname").toString();
            
            if(firstName != null){
                out.println(firstName);
              } else {
                out.println("No text entered.");
              }
            
            if(surname != null){
                out.println(firstName);
              } else {
                out.println("No text entered.");
              }
        	}

  3. #3
    Unni is offline Member
    Join Date
    Jul 2007
    Posts
    6
    Rep Power
    0

    Default Blank result for jsp servlet in Eclipse

    Thank you so much Albert :)

    I could run and got the answer.. Thanks for ur immediate reply.. I couldnt reply early since i went to my native..

    and am expecting more from u.. nice to meet u..

    Once again Thanks!!

    Regards
    Juni

Similar Threads

  1. how can we remove blank lines from a .txt
    By Camden in forum New To Java
    Replies: 12
    Last Post: 07-29-2011, 02:38 PM
  2. Iterating through result set in JSTL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 04:13 PM
  3. Iterating through result set in JSTL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 10:31 AM
  4. Print a blank space
    By susan in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 02:58 PM
  5. getting a random result
    By gradon in forum New To Java
    Replies: 2
    Last Post: 07-19-2007, 04:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •