Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Friday

Create & Run java server page(jsp) in IDE

0 comments
how to create jsp- Dynamic web application in Eclipse or Netbeans IDE
step-1
            File - New WebApplication
               Create a new web application  & name it.
 
to create jsp dynamic web application





                    click finish proceed to next step
 Step-2
          Right click the Web application from project Hierarchy  in right side
                 -select New -> JSP File

           <%  out.println("Hello - Pradeesh");   %>

Saturday

Servlets Connection with Mysql using JDBC

0 comments
   How to connect servlets with mysql?.Servlet program to connect to mysql database using jdbc Driver in Eclipse

If you have problem in executing servlet code, see this tutorial.


Import external jar files
  •            javax.servlet-api-3.0.1.jar
  •            mysql connector / J
To know how to import external jar to project, go here (step 5).


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.*;
import java.sql.*;

@WebServlet("/dbconnect")

public class dbconnect extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
try
{

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

String URL = "jdbc:mysql://localhost:3306/mysql";
Connection connection = null;
// Load JBBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(URL, "root", "v");

if(!connection.isClosed())
    out.println("Successfully connected to " + "MySQL server using TCP/IP...");

else
    out.println("No connection");

}

catch(Exception excp)
{
excp.printStackTrace();
}

}}





java servlet
Hope you already configured webserver (I ve tomcat7) which is needed to execute Dynamic web projects ....if not go here .

Related post :


   servlet program to get html form data
 
    Servlet with doget method

How to create servlets in Eclipse

0 comments
   How to write & execute servlets code in eclipse ,Netbeans IDE. Don't confuse with web.xml file, eclipse can automatically generate it.Develop java servlets with tomcat.

Now, Let us start with simple Hello world program in servlets .

1. File-> New ->  Dynamic web project
Name the project as Helloworld.

2. Click next, you will get a window as follow  there check in the option Generate web.xml.


Don't Forget To Join US Our Community
×
blogger