我的教授给了我一个简单的HTML表单的作业,提交到CGI程序(使用c ++ gnu库cgicc),无论我尝试多少次修复,每当我在HTML页面中调用该程序时,我都会得到服务器错误500:标题之前的脚本输出结束:submit.cgi。
这是我的submit.cpp(编译生成submit.cgi的文件)
#include<iostream>
#include<vector>
#include<string>
#include"cgicc/Cgicc.h"
#include"cgicc/HTTPHTMLHeader.h"
#include"cgicc/HTMLClasses.h"
using namespace std;
using namespace cgicc;
int main(int argc, char** argv)
{
Cgicc cgi;
cout << HTTPHTMLHeader() << endl; //Header
cout << html() <<head (title("Submitted Form Data")) << endl; // Head
cout << body() << endl; //<body>
//Submitted Elements are Printed
form_iterator rname = cgi.getElement("restaurant_name");
if(rname != cgi.getElements().end())
{
cout << "Restaurant Name: " << **rname << "<br>" << endl;
}
form_iterator city = cgi.getElement("city");
if(city != cgi.getElements().end())
{
cout << "City: " << **city << "<br>" << endl;
}
form_iterator state = cgi.getElement("state");
if(state != cgi.getElements().end())
{
cout << "State: " << **state << "<br>" << endl;
}
form_iterator postcode = cgi.getElement("postcode");
if(postcode != cgi.getElements().end())
{
cout << "Postcode: " << **postcode << "<br><br>" << endl;
}
form_iterator cuisine = cgi.getElement("cuisine");
if(cuisine != cgi.getElements().end())
{
cout << "Type of Cuisine: " << **cuisine << "<br>" << endl;
}
form_iterator cost = cgi.getElement("cost");
if(cost != cgi.getElements().end())
{
cout << "Cost: $" << **cost << "0<br><br>" << endl;
}
form_iterator food = cgi.getElement("food");
if(food != cgi.getElements().end())
{
cout << "Food Rating: " << **food << "<br>" << endl;
}
form_iterator service = cgi.getElement("service");
if(service != cgi.getElements().end())
{
cout << "Service Rating: " << **service << "<br>" << endl;
}
form_iterator ambience = cgi.getElement("ambience");
if(ambience != cgi.getElements().end())
{
cout << "Ambience Rating: " << **ambience << "<br>" << endl;
}
form_iterator value = cgi.getElement("value");
if(value != cgi.getElements().end())
{
cout << "Value for Money Rating: " << **value << "<br><br>" << endl;
}
form_iterator date = cgi.getElement("date");
if(date != cgi.getElements().end())
{
cout << "Last Visited on: " << **date << "<br>" << endl;
}
form_iterator comments = cgi.getElement("comments");
if(comments != cgi.getElements().end())
{
cout << "Comments: " << **comments << "<br>" << endl;
}
cout << body() << html(); //closes HTML document
}
我的HTML页面
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Restaurant Reviews</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="style.css" rel="stylesheet" type="text/css"/>
<script src="datacheck.js" type="text/javascript"></script>
</head>
<body>
<div>
<h1 class="head">Restaurant Reviews</h1>
</div>
<div>
<form onsubmit="datacheck()" method="post" action="/cgi-bin/submit.cgi">
<fieldset class="formbox">
<legend>Restaurant Details</legend>
Enter the details of the Restaurant you ate at/ordered from:<br>
Name of Restaurant: <input type="text" id="restaurant_name" name="restaurant_name"><br>
City: <input type="text" id="city" name="city" /><br>
State/Territory:
<select name="state" id="state">
<option value="nsw">New South Wales</option>
<option value="qld">Queensland</option>
<option value="act">Australian Capital Territory</option>
<option value="vic">Victoria</option>
<option value="tas">Tasmania</option>
<option value="sa">South Australia</option>
<option value="nt">Northern Territory</option>
<option value="wa">Western Australia</option>
</select>
<br>
Postcode: <input type="text" name="postcode" id="postcode">
</fieldset>
<fieldset class="formbox">
<legend>Cuisine Details</legend>
Please describe the type of Cuisine you ordered:<br>
Type of Cuisine:
<select name="cuisine" id="cuisine">
<option value="0">Select a Cuisine</option>
<option value="aussie">Australian</option>
<option value="greek">Greek</option>
<option value="italian">Italian</option>
<option value="chinese">Chinese</option>
<option value="thai">Thai</option>
<option value="other">Other</option>
</select>
<br>
Cost: <input type="number" min ="1.0" max="100.0" step ="0.10"
name="cost" id="cost"><br>
</fieldset>
<fieldset class="formbox">
<legend>Ratings</legend>
Please rate your restaurant experience between 0 - 10<br>
Food: <input type="number" min ="1.0" max="10.0" step ="0.10"
name="food" id="food"><br>
Service: <input type="number" min ="1.0" max="10.0" step ="0.10"
name="service" id="service"><br>
Ambience: <input type="number" min ="1.0" max="10.0" step ="0.10"
name="ambience" id="ambience"><br>
Value for Money:<input type="number" min ="1.0" max="10.0" step ="0.10"
name="value" id="value"><br>
</fieldset>
<fieldset class="formbox">
<legend>Your Review</legend>
Date of your last visit (DD-MM-YYYY): <input type="text" name="date" id="date"><br><br>
Comments: <br>
<textarea rows="4" cols="50" name="comments" id="comments">
Enter comments on your experience here.
</textarea><br>
<input type="submit" value="Submit Review" >
</fieldset>
</form>
</div>
</body>
</html>
我的相关JS
function datacheck()
{
var error = "There are errors in your form. They are; ";
var postcode = 0;
var charerr = 0;
var dateerr = 0;
var retval = false;
postcode = statecheck();
charerr = charcheck();
dateerr = datecheck();
if (postcode !== 0)
{
error += "Postcode does not match range of entered State/Territory. ";
}
if (charerr !== 0){
error += "Form cannot contain < or > or & characters. ";
}
if (dateerr !== 0)
{
error += "Date format was incorrect. Please use DD-MM-YYYY.";
}
if (dateerr !== 0 || charerr !== 0 || postcode !== 0)
{
window.alert(error);
}
else
{
window.alert("Form Submitted Sucessfully!");
retval = true;
}
return retval;
}
function statecheck()
{
var state;
var postcode;
var errval = 0;
state = document.getElementById("state").value;
postcode = document.getElementById("postcode").value;
if (state === "nsw"){
if((postcode <2000) ||(postcode > 2999))
{
errval = 1;
}
}
else if (state === "qld")
{
if ((postcode < 4000) || (postcode > 4999))
{
errval = 1;
}
}
else if (state === "vic")
{
if ((postcode < 3000)||(postcode>3999))
{
errval = 1;
}
}
else if (state === "tas")
{
if ((postcode < 7000) || (postcode > 7999))
{
errval = 1;
}
}
else if (state === "wa")
{
if ((postcode < 6000) || (postcode > 6999))
{
errval = 1;
}
}
else if (state === "sa")
{
if ((postcode < 5000) || (postcode > 5999))
{
errval = 1;
}
}
else if (state === "nt")
{
if ((postcode < 800) || (postcode > 999))
{
errval = 1;
}
}
else if (state === "act")
{
if ((postcode < 2600) || (postcode > 2618))
{
if ((postcode <2900)||(postcode>2999))
{
errval = 1;
}
}
}
return errval;
}
function charcheck()
{
var rname;
var city;
var comments;
var errval = 0;
rname = document.getElementById("restaurant_name").value;
city = document.getElementById("city").value;
comments = document.getElementById("comments").value;
if(rname.match('<'))
{
errval = 1;
}
else if(rname.match('>'))
{
errval = 1;
}
else if(rname.match('&'))
{
errval = 1;
}
if(city.match('<'))
{
errval = 1;
}
else if(city.match('>'))
{
errval = 1;
}
else if(city.match('&'))
{
errval = 1;
}
if(comments.match('<'))
{
errval = 1;
}
else if(comments.match('>'))
{
errval = 1;
}
else if(comments.match('&'))
{
errval = 1;
}
return errval;
}
function datecheck()
{
var errval = 0;
var date;
date = document.getElementById("date").value;
if (isNaN(date[0]))
{
errval = 1;
}
if (isNaN(date[1]))
{
errval = 1;
}
if (date[2] !== '-')
{
errval = 1;
}
if (isNaN(date[3]))
{
errval = 1;
}
if (isNaN(date[4]))
{
errval = 1;
}
if (date[5] !== '-')
{
errval = 1;
}
if (isNaN(date[6]))
{
errval = 1;
}
if (isNaN(date[7]))
{
errval = 1;
}
if (isNaN(date[8]))
{
errval = 1;
}
if (isNaN(date[9]))
{
errval = 1;
}
return errval;
}