aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes how to run this servlet file in netBeans IDE 6.9.1 ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "how to run this servlet file in netBeans IDE 6.9.1 ?" Watch "how to run this servlet file in netBeans IDE 6.9.1 ?" New topic
Author

how to run this servlet file in netBeans IDE 6.9.1 ?

Trupti brane
Greenhorn

Joined: Aug 16, 2011
Posts: 20

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.ServletConfig;
//import java.util.*;
public class CookieServlet extends HttpServlet {
public void init(ServletConfig config)throws ServletException{
super.init(config);
}

private String getCurrentUser(String value)
{
String userName=new String(" ");

if(value.equals("564xx892"))
{
userName=new String("Trupti");
}
return userName;

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{

Cookie[] cookielist=request.getCookies();
String user=null;
String responseString=null;

if(cookielist!=null)
{
for(int x=0;x<cookielist.length;x++)
{
String name=cookielist[x].getName();

if(name.equals("session_id"))
{
user=getCurrentUser(cookielist[x].getValue());
break;
}
}
}

if(user==null)
{
response.addCookie(new Cookie("session_id","564xx892"));
responseString=new String("welcome to our site,"+"we have created session for you");
}
else
{
responseString=new String ("hello"+user);
}
response.setContentType("html/text");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head><title>CookieServlet</title></head>");
out.println("<body>");
out.println(responseString);
out.println("</body>");
out.println("</html>");
out.close();
}



public String getServletInfo()
{
return "CookieServlet information";
}// </editor-fold>

}


i wanted to run this file in IDE netBeans.i know how to run html file which will show the output in browser immediately after running.but this is .java file which i am unable to see in browser.soon after i run this file my browser download this file and ask me to select the program to open the file.
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Maybe this link will help you:
http://www.java-tips.org/java-tutorials/tutorials/introduction-to-java-servlets-with-netbeans.html

Next time you post, you coud wrap your code in the code tags. It will be easier to read. [=


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to run this servlet file in netBeans IDE 6.9.1 ?