![]() | เจเอสพี จาวาเซิร์ฟเวอร์เพจ JSP,Servlet,ODBC,Tomcat | ![]() |
|
ภาษาเจเอสพี (JSP = Java Server Pages) [ reference ]
แนะนำเว็บ (Web Guides) + Session Tutorial + http://www.watchai.com/cmm271/JSP1.ppt + http://www.chontech.ac.th/~worakit/iit_nu/s_ad_java/L02-SERVLET%20Part%201-v7.ppt + http://www.jarticles.com/tutorials/servlet/intro_servlet.html + Root ของ Java 5 วิธีติดตั้ง TOMCAT Apache Web Server ใน thaiall.com/server (ไม่พบปัญหาใน Tomcat 5.0.27) PowerPoint เตรียมสอน JSP jsp2005.zip ที่ ม.เทคโนโลยีราชมงคล ลำปาง 3 ชั่วโมง
|
| ![]() - th.lge.com - truelife.com - airasia.com - amway.co.th - bellshopping.com - กรมศุลกากร - dsi.go.th - krisdika.go.th - labour.go.th - สำนักงานสถิติแห่งชาติ - ตลาดหลักทรัพย์ - sipaphuket.org - sonyericsson.com - thaiair.com - thaiechamber.com - thailocaladmin.go.th - truecorp.co.th แฟ้มสำหรับ Java 5.0 + servlet-api.jar |
|
ยินดีรับ ผู้สนับสนุน เว็บไซต์ด้านการศึกษา
กลุ่มเว็บไซต์นี้ เริ่มพัฒนา พ.ศ.2542 โดยบุคลากรทางการศึกษาด้านคอมพิวเตอร์ โทร. 081-9927223 (ผมเป็นคนลำปางหนา) ปล. ขอไม่รับ work at home / อาหารเสริม |
| |||||||||||||||||||||||||
Servlet Testing
1. To compile hi.java
c:\Tomcat5\webapps\servlets-examples\WEB-INF\classes>path=%path%;c:\j2sdk1.4.0_03\bin
c:\Tomcat5\webapps\servlets-examples\WEB-INF\classes>javac -classpath c:\Tomcat5\common\lib\servlet-api.jar hi.java
2. Change c:\Tomcat5\webapps\servlets-examples\WEB-INF\web.xml
<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>
<servlet>
<servlet-name>hi</servlet-name>
<servlet-class>hi</servlet-class>
</servlet>
:::::::
:::::::
<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/servlet/HelloWorldExample</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>hi</servlet-name>
<url-pattern>/servlet/hi</url-pattern>
</servlet-mapping>
3. Start tomcat and open the servlet file
|
| รวมโปรแกรมเบื้องต้น ด้วยภาษาเจเอสพี (JSP Language) |
<body><pre> <% Random r = new Random(); out.println(r.nextInt(10)); %> </pre></body> | |||||
<body><pre>
<%
for (int i=1;i<=10;i++)
{
out.println(i);
}
%>
</pre></body>
| |||||
<body>
<form action=x.jsp method=get>
<input name=x><input type=submit></form>
<%
String abc = request.getParameter("x");
out.println(abc);
%>
</body>
| |||||
<body>
<form action=testofif.jsp method=post>
<input name=x><input type=submit></form>
<%
String abc = request.getParameter("x");
if (abc == null)
out.println("welcome");
else
out.println(abc);
out.println(new java.util.Date());
%>
</body>
| |||||
<body>
<%@ page import="java.sql.*" %>
<%
Connection connection;
Statement statement;
String sourceURL = "jdbc:odbc:empl";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(sourceURL);
statement = connection.createStatement();
String sql = "select * from empl";
ResultSet myresult = statement.executeQuery(sql);
while (myresult.next()) {
out.println(myresult.getString("emplid") + "<br>");
}
myresult.close();
%>
</body>
| |||||
<body>
<%@ page
import="java.sql.*"
import = "java.lang.*"
%>
<%
Connection connection;
Statement statement;
String sourceURL = "jdbc:odbc:empl";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(sourceURL);
statement = connection.createStatement();
String sql = "select * from empl";
ResultSet myresult = statement.executeQuery(sql);
int sala,tmpsala;
sala = 0;
while (myresult.next()) {
out.print(myresult.getString("emplid") + "|");
out.print(myresult.getString("emplname") + "|");
tmpsala = myresult.getInt("emplsalary");
out.println(tmpsala +"<br>");
sala = sala + tmpsala;
}
out.println(sala);
myresult.close();
%>
</body>
| |||||
<%@ page contentType="text/html; charset=tis-620" %>
<%@ page import="java.sql.*" %>
<body>
<%
Connection connection;
Statement statement;
String sourceURL = "jdbc:odbc:empl";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(sourceURL);
statement = connection.createStatement();
String sql = "select * from empl";
ResultSet myresult = statement.executeQuery(sql);
while (myresult.next()) {
out.println(myresult.getString("emplname") + "<br>");
}
myresult.close();
%>
</body>
| |||||
<body>
<%@ page import="java.sql.*" %>
<%
Connection connection;
Statement statement;
String sourceURL = "jdbc:odbc:empl";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(sourceURL);
statement = connection.createStatement();
String sql = "select * from empl";
ResultSet myresult = statement.executeQuery(sql);
while (myresult.next()) {
out.println(myresult.getString("emplid") + "<br>");
}
myresult.close();
} catch (SQLException e) {
out.println("Error creating connection or have problem on odbc");
} catch (ClassNotFoundException e) {
out.println("Driver of Database not found");
}
%>
</body>
| |||||
<body>
<%@ page import="java.sql.*" %>
<%
String methodtype = request.getParameter("action");
if (methodtype == null) {
out.println(request.getParameter("comment"));
%>
<form action=addthainame.jsp method=post>
employee id : <input name=eid><br>
employee name : <input name=ename><br>
employee salary : <input name=esalary><br>
Add confirmed : <input type=checkbox name=confirm checked>
<input type=submit name=action value=add>
</form>
<%
} else {
Connection connection;
Statement statement;
String sourceURL = "jdbc:odbc:empl";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(sourceURL);
statement = connection.createStatement();
String getname = request.getParameter("ename");
String thainame = new String(getname.getBytes("ISO8859_1"),"TIS-620");
String sql = "insert into empl values(";
sql = sql + request.getParameter("eid") + ",'";
sql = sql + thainame + "',";
sql = sql + request.getParameter("esalary") + ")";
if (request.getParameter("confirm") == null) {
out.println(sql);
} else {
statement.executeUpdate(sql);
response.sendRedirect("addthainame.jsp?comment=add_completly");
}
}
%>
</body>
| |||||
<%@ page import="java.sql.*" %>
<%
Connection connection;
Statement statement;
String sourceURL = jdbc:mysql://localhost/dbempl?user=root&password=thai;
Class.forName (org.gjt.mm.mysql.Driver);
connection = DriverManager.getConnection(sourceURL);
statement = connection.createStatement();
String sql = "select * from empl";
ResultSet myresult = statement.executeQuery(sql);
while (myresult.next()) {
out.println(myresult.getString("emplid") + "<br>");
}
myresult.close();
%>
| |||||
<%@ page import="java.sql.*" %> <% Connection connection; String sourceURL = jdbc:mysql://localhost/dbempl?user=root&password=thai; Class.forName (org.gjt.mm.mysql.Driver); connection = DriverManager.getConnection(sourceURL); Statement statement = connection.createStatement(); String sql = "delete * from empl"; ResultSet myresult = statement.executeQuery(sql); myresult.close(); %> | |||||