Jump to content

Base de Dados e JavaServerPage


Recommended Posts

JSP e Servlets - http://revista-programar.info/?action=index&type=viewpost&n=51

Ligação a base de dados - http://www.portugal-a-programar.pt/topic/61714-conexao-base-de-dados/

Isto são exemplos base sem adição se nenhuma framework

Para ligares as duas coisas basta criar uma class que contenha todos os métodos que trabalham sobre a base de dados e criar uma servlet que inicialize a mesma

Deste género

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import com.db.InterfaceDB;
public class InitServlet extends HttpServlet {
public static InterfaceDB db;
public void init() throws ServletException {
	try {
		db = new InterfaceDB();
	} catch (Exception e) {
		throw new ServletException("ERROR!: Couldn't initialize Data Base", e);

e colocares o seguinte mapeamento no web.xml

	<servlet-name>InitServlet</servlet-name> //a name
	<servlet-class>com.servlet.InitServlet</servlet-class> //class package path
	<load-on-startup>1</load-on-startup> //defines class instanciation when the application starts

The worst part of censorship is ****

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.