Advertisement
2_2002-2004 Miscellaneous #126338

Online School Registration Java Servlet

Simple example of a java servlet. This is a "tone-downed" version of a servlet I created for a school in the South. I figured maybe someone out there may get some use out of it, or maybe not. If you do, have fun with it. If you want use this, remember to create your DBMS (ie, MSACCESS).

AI

Ringkasan AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kode Sumber
original-source
///////////////////////////////////////////////////////////////////////////
//Title: Online Registration Servlet
//Author: Steven Jacobs
//Dev. Tools: JBuilder3..JDK 1.2
//Description: This is a mock-up version of an online registration servlet
//    for any university. It is similar to an online family reservation
//    servlet I created about 7 months ago. I thought I would take about
//    an hour to do this and share it with you. Maybe you can get
//    something out of it. Please improve.
////////////////////////////////////////////////////////////////////////////
package untitled28;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class OnlineRegsServlet extends HttpServlet
{
 private Statement conStatement = null;
 private Connection conDatabase = null;
 private String odbcURL = "jdbc:odbc:RegsBook";
 String name;
 String classStanding;
 String term;
 String year;
 String class1;
 String class2;
 String class3;
 String class4;
 String class5;
 String class6;
 PrintWriter outWrite;
 //Initialize global variables
 public void init(ServletConfig config) throws ServletException
 {
 super.init(config);
 try
 {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  conDatabase = DriverManager.getConnection(odbcURL, " ", " ");
 }
 catch (Exception e)
 {
  e.printStackTrace();
  conDatabase = null;
 }
 }
 public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
 {
 //String name,classStanding,term,year,class1,class2,class3,class4,class5,class6;
 name = request.getParameter("Name");
 classStanding = request.getParameter("Class_Standing");
 term = request.getParameter("Term");
 year = request.getParameter("Year");
 class1 = request.getParameter("Class1");
 class2 = request.getParameter("Class2");
 class3 = request.getParameter("Class3");
 class4 = request.getParameter("Class4");
 class5 = request.getParameter("Class5");
 class6 = request.getParameter("Class6");
 outWrite = response.getWriter();
 response.setContentType("text/html");
 if (name.equals("") || classStanding.equals("") || term.equals("") ||
  year.equals(""))
 {
  outWrite.println("<H3>All the fields '*' fields must be filled out</H3>");
  outWrite.close();
  return;
 }
 boolean insertSuccess = inputInformation(
 "'" + name + "','" + classStanding + "','" + term + "','" + year +
 "','" + (class1 != null ? "yes" : "no") + "','" +
 (class2 != null ? "yes" : "no") + "','" +
 (class3 != null ? "yes" : "no") + "','" +
 (class4 != null ? "yes" : "no") + "','" +
 (class5 != null ? "yes" : "no") + "','" +
 (class6 != null ? "yes" : "no") + "'");
 if (insertSuccess)
 {
 outWrite.print("<H2> "+ name + " is registered for the " + term + " term " +
    ", " + year + "</H2>");
 }
 else
  outWrite.print("<H2>Server error...try again later.</H2>");
}
private boolean inputInformation(String insertInfo)
{
 try
 {
 conStatement = conDatabase.createStatement();
 conStatement.execute("INSERT INTO RegTable values(" + insertInfo + ");");
 conStatement.close();
 }
 catch(Exception e)
 {
 System.err.println("Something is wrong..I cannot add any new entry " +
 "HELP ME");
 e.printStackTrace();
 return false;
 }
 return true;
}
public void destroy()
{
 try
 {
 conDatabase.close();
 }
 catch (Exception e)
 {
 System.err.println("Cannot close the database");
 }
}
 //Get Servlet information
 public String getServletInfo()
 {
 return "untitled28.OnlineRegsServlet Information";
 }
}
/*
Aaron M. Ataman
11jan01
ascii.cpp
	This simple program uses 
	a nested for loop to format
	and display the ASCII standard
	of character values.
Input: None
Output: ASCII table
Processing: 
	Nested for loop structure
	allows simple, efficent 
	displaying and formatting
	of the ASCII table.
*/
#include <iostream.h> // necissary for i/o
void printASCII()
{ // begin printASCII
int i,j;
for (i=32;i<255;i+=7)
{ 
for(j=0;j<7;j++)
{
cout << i+j << ": " << char(i+j) << " ";
}
cout << endl; // carrige return (for formatting)
}// end printASCII

}
void main()
{
printASCII();
}
Upload
Komentar Asli (3)
Dipulihkan dari Wayback Machine