Q:

Unable to redirect to external URL's (like google.com) in my Servlet program

Here in my program, I am taking input from user using URL- Re-writing method.  For example if user enters company name as google, the program develops an URL as www.google.com which can be called by the user.  But the problem here is here.  I am unable to call www.google.com rather it calls localhost:8080/Myproject/www.google.com.  For more clarity refer to my screenshots as well.  Thanks. 
Two java Programs 1.  Login.java
import javax.servlet.*; 
import javax.servlet.http.*; 
import java.io.*; 
import java.util.*; 

public class Login extends HttpServlet{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
    String Company=req.getParameter("Company");

    PrintWriter pw=res.getWriter();
    pw.println("<html>");
    pw.println("<body bgcolor='green'>");

    pw.println("<p>YOUR ARE LOGGED INTO THE "+ Company +" Sucessfully</p>");
    pw.println("<a href='./Website?Cname="+Company+"'>VISIT</a>");

    pw.println("</body>");
    pw.println("</html");
    pw.close();
 }
}

2.  Website.java  
import javax.servlet.*; 
import javax.servlet.http.*; 
import java.io.*; 
import java.util.*; 

public class Website extends HttpServlet{
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{

        String Company=req.getParameter("Cname");

        PrintWriter pw=res.getWriter();

        pw.println("<html>");
        pw.println("<body bgcolor='grey'>");

        String Website="www. "+Company+".com";
        pw.println("Website URL="+Website);

        pw.println("<a href='www. "+Company+".com'>Website</p>");

        pw.println("</body>");
        pw.println("</html");
        pw.close();

    }
}

My html code for input
<html>
<body bgcolor='pink'>
    <center>
        <form method="post" action="./Login">
            Enter your Company Name:<input type="text" name="Company">
            <input type="submit" Value="SUBMIT">
        </form>
    </center>
</body>

My web.xml file for Servlet
    <web-app>
    <servlet>
        <servlet-name>SA</servlet-name>
        <servlet-class>Login</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>SA</servlet-name>
        <url-pattern>/Login</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>SB</servlet-name>
        <servlet-class>Website</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>SB</servlet-name>
        <url-pattern>/Website</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
    <welcome-file>Images.html</welcome-file>
    </welcome-file-list>

</web-app>

The image are numbered as per the call that is taking place.  If you refer to the 4th screenshot, the url reads as 'http://localhost:8080/CompanyImages/www.google.com', but the expectation is to read the URL, 'www.google.com
 

A:

I think you need to change your code like this
<a href ="http://www.google.com"><p>Website</p></a>
Because if tag href don't have http:// then your program will understand it is a servlet name. In addition,You have to close your html Tag.  For example:
<a>content</a> or <b>content</b>

