/Courses and labs samples/SCD/Servlet/WebApp/.classpath |
New file
@@ -0,0 +1,14 @@ |
<?xml version="1.0" encoding="UTF-8"?> |
<classpath> |
<classpathentry kind="src" path="src"/> |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> |
<attributes> |
<attribute name="owner.project.facets" value="java"/> |
</attributes> |
</classpathentry> |
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> |
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> |
<classpathentry kind="lib" path="D:/temp/apache-tomcat-7.0.57/lib/servlet-api.jar"/> |
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/mysql-connector-java-5.1.25-bin.jar"/> |
<classpathentry kind="output" path="build/classes"/> |
</classpath> |
/Courses and labs samples/SCD/Servlet/WebApp/.project |
New file
@@ -0,0 +1,36 @@ |
<?xml version="1.0" encoding="UTF-8"?> |
<projectDescription> |
<name>WebApp</name> |
<comment></comment> |
<projects> |
</projects> |
<buildSpec> |
<buildCommand> |
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name> |
<arguments> |
</arguments> |
</buildCommand> |
<buildCommand> |
<name>org.eclipse.jdt.core.javabuilder</name> |
<arguments> |
</arguments> |
</buildCommand> |
<buildCommand> |
<name>org.eclipse.wst.common.project.facet.core.builder</name> |
<arguments> |
</arguments> |
</buildCommand> |
<buildCommand> |
<name>org.eclipse.wst.validation.validationbuilder</name> |
<arguments> |
</arguments> |
</buildCommand> |
</buildSpec> |
<natures> |
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> |
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> |
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> |
<nature>org.eclipse.jdt.core.javanature</nature> |
<nature>org.eclipse.wst.jsdt.core.jsNature</nature> |
</natures> |
</projectDescription> |
/Courses and labs samples/SCD/Servlet/WebApp/src/exemple/scd/web/AdaugaPersoanaServlet.java |
New file
@@ -0,0 +1,33 @@ |
package exemple.scd.web; |
|
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; |
|
/** |
* Servlet implementation class AdaugaPersoanaServlet |
*/ |
@WebServlet(name = "adaugaPersoana", urlPatterns = { "/adaugaPersoana" }) |
public class AdaugaPersoanaServlet extends HttpServlet { |
private static final long serialVersionUID = 1L; |
|
/** |
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
*/ |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
String nume = request.getParameter("nume"); |
String prenume = request.getParameter("prenume"); |
|
PrintWriter out = response.getWriter(); |
|
out.println("Hello "+nume+" "+prenume); |
out.close(); |
|
} |
|
} |
/Courses and labs samples/SCD/Servlet/WebApp/src/exemple/scd/web/HelloWorldServlet.java |
New file
@@ -0,0 +1,53 @@ |
package exemple.scd.web; |
|
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; |
|
/** |
* Servlet implementation class HelloWorldServlet |
*/ |
@WebServlet(name = "hello", urlPatterns = { "/hello" }) |
public class HelloWorldServlet extends HttpServlet { |
private static final long serialVersionUID = 1L; |
|
int counter = 0; |
/** |
* @see HttpServlet#HttpServlet() |
*/ |
public HelloWorldServlet() { |
super(); |
// TODO Auto-generated constructor stub |
} |
|
/** |
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
*/ |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
counter++; |
response.setContentType("text/html"); |
PrintWriter out = response.getWriter(); |
out.println("<html>"); |
out.println("<head>"); |
out.println("<title>Hello World!</title>"); |
out.println("</head>"); |
out.println("<body>"); |
out.println("<h1>Hello World!</h1>"); |
out.println("<h3>You are visitor number:"+counter+"</h3>"); |
out.println("</body>"); |
out.println("</html>"); |
} |
|
/** |
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
*/ |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
// TODO Auto-generated method stub |
} |
|
} |
/Courses and labs samples/SCD/Servlet/WebApp/src/exemple/scd/web/AdaugaPersoana2Servelet.java |
New file
@@ -0,0 +1,53 @@ |
package exemple.scd.web; |
|
import java.io.IOException; |
import java.io.PrintWriter; |
import java.sql.Connection; |
import java.sql.DriverManager; |
import java.sql.SQLException; |
import java.sql.Statement; |
|
import javax.servlet.ServletConfig; |
import javax.servlet.ServletException; |
import javax.servlet.annotation.WebServlet; |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
|
/** |
* Servlet implementation class AdaugaPersoana2Servelet |
*/ |
@WebServlet(name = "adaugaPersoana2", urlPatterns = { "/adaugaPersoana2" }) |
public class AdaugaPersoana2Servelet extends HttpServlet { |
private static final long serialVersionUID = 1L; |
private Connection con; |
/** |
* @see Servlet#init(ServletConfig) |
*/ |
public void init(ServletConfig config) throws ServletException { |
try{ |
Class.forName("com.mysql.jdbc.Driver"); |
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/webapp?user=root"); |
}catch(Exception e){ |
e.printStackTrace(); |
} |
} |
|
/** |
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
*/ |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
String nume = request.getParameter("nume"); |
String prenume = request.getParameter("prenume"); |
PrintWriter out = response.getWriter(); |
try{ |
Statement s = con.createStatement(); |
s.executeUpdate("INSERT INTO PERSOANE VALUES('"+nume+"','"+prenume+"')"); |
out.println("Inregistrarea a fost adaugata"); |
}catch(SQLException e){ |
out.println("A aparut o eroare pe server la introducere date:"+e.getMessage()); |
|
} |
} |
|
} |
/Courses and labs samples/SCD/Servlet/WebApp/WebContent/WEB-INF/web.xml |
New file
@@ -0,0 +1,12 @@ |
<?xml version="1.0" encoding="UTF-8"?> |
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> |
<display-name>WebApp</display-name> |
<welcome-file-list> |
<welcome-file>index.html</welcome-file> |
<welcome-file>index.htm</welcome-file> |
<welcome-file>index.jsp</welcome-file> |
<welcome-file>default.html</welcome-file> |
<welcome-file>default.htm</welcome-file> |
<welcome-file>default.jsp</welcome-file> |
</welcome-file-list> |
</web-app> |