int main(void)
{
char *data;
long m,n;
printf("%s%c%c\n", "Content-Type:text/html",13,10);
printf("<TITLE>Multiplication results</TITLE>\n");
printf("<H3>Multiplication results</H3>\n");
data = getenv("QUERY_STRING");
if(data == NULL)
printf("<P> Error in passing data from form to script.");
else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
printf("<P>Error! Invalid data. Data must be numeric.");
else
printf("<P>The product of %ld and %ld is %ld.",m,n,m*n);
return 0;
}
Embedded JavaScript Template #
<%# index.ejs %>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<div class="message">
<%= message %>
</div>
<% if (showSecret) { %>
<div>my secret</div>
<% } %>
</body>
</html>
$ npm install --save ejs
app.set('view engine', 'ejs')
const data = {
title: 'Template Language',
message: 'Hello EJS!',
showSecret: true
}
res.render('index.ejs', data)
// `public` 폴더에 있는 파일을 `/static` 경로 아래에서 제공
app.use('/static', express.static('public'))
<!-- 템플릿 파일에서 참조할 수 있음 -->
<link rel="stylesheet" href="/static/index.css">
<script type="text/javascript" src="/static/index.js"></script>