Hi Daniweb team,
I am developing the sample servlet program.This is my sample program.

Servlet Code:

package org;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
    public class HelloWorld extends HttpServlet{
            public void doGet(HttpServletRequest req,HttpServletResponse rsp)throws ServletException,IOException{
                 PrintWriter out=rsp.getWriter();
                String type=req.getParameter("type");
                if(type==null){
                        out.print("success");
                }
                else{
                        out.println("Not a Null value");
                }
         }
       }

I want to pass the values through URL and check whether the given parameters are null.
I am using the apache tomcat server.

I have mentioned url below:
http://ipaddress/HelloWorld/src/HelloWorld.java?type=1

When i execute the above url the full code is displayed in the browser.Can any one know how to execute this above code.There is no error in the above code and i executed successfully the class file is also generated.

Thank you,

Regards,
Premnath.M

http://ipaddress/HelloWorld/src/HelloWorld.java?type=1

This url looks like it points to a java source program. I would expect that the server would read the source file and return it to your browser.
If you want to execute your servlet, you need the URL that points to that servlet.

Be a part of the DaniWeb community

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