
Санкт-Петербургский государственный университет информационных технологий, механики и оптики
Кафедра вычиcлительной техники
Системы программирования интернет-приложений
Лабораторная работа №5
«HTML и CSS»
Вариант 340
Выполнили:
студенты группы 4103
Пермяков Валерий
Голубцов Евгений
Рябинина Александра
2011
Код HTML-страницы со скриптом:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Group 4103 Variant №340 </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="style.css" rel="stylesheet" type="text/css" />
<script>
flpoint=false;
flmin=false;
function SetPos(Obj){
Obj.setSelectionRange(Obj.value.length,Obj.value.length);
}
function validate(Obj) {
len=Obj.value.length;
if (len==16) {event.returnValue=false; return 0;}
if ((event.keyCode==45) && (len==0)){
flmin=true;
return 0;
}
if ((event.keyCode==46)&&(!flpoint)&&(len>0)&&!(flmin&&len==1)){
flpoint=true;
return 0;
}
str=Obj.value.toString();
var st=String.fromCharCode(event.keyCode);
if (event.keyCode==8) {
if (str[len-1]=='.') {flpoint=false;}
if (len==1) flmin=false;
return 0;
}
if ((event.keyCode<48)||(event.keyCode>57)){event.returnValue=false;}
else {
str=str+st;
i=parseFloat(str);
if ((i<=-3)||(i>=3)) event.returnValue=false;
}
}
function isEmpty(str) {
for (var i = 0; i < str.length; i++)
if (" " != str.charAt(i))
return false;
return true;
}
function checkform (forma){
var errMSG = "";
for (var i = 0; i<forma.elements.length; i++) {
if (null!=forma.elements[i].getAttribute("required")) {
if (isEmpty(forma.elements[i].value))
errMSG += " " + forma.elements[i].name + "\n";
}
if ("" != errMSG) {
alert("Area is Empty:\n" + errMSG);
return false;
}
}
}
</script>
</head>
<body>
<table width="800px" border="1" align="center" cellpadding="0" cellspacing="0" class="main_border">
<tr>
<td width="800px" height="150" bgcolor="#111111">
<CENTER>
<font color="#CCCCCC">
Рябинина А. Голубцов Е. Пермяков В.<BR>
Гр. 4103<BR>
Вар. №340
</font>
</CENTER>
</td>
</tr>
<tr>
<td width="600px" align="left" valign="top" bgcolor="#CCCCCC">
<CENTER><font>№5 </font></CENTER>
<form id="form1" name="form1" method="GET" action="http://localhost:8080/test_servlet/First_servlet" onSubmit = "return checkform(this)">
<CENTER><font>Point coordinates:</font></CENTER>
<HR color="#000000" width="100" align="center" >
<BR>
<Label class="label1">Х: </Label>
<select name="param1" class="select1">
<option value="-5">-5
<option value="-4">-4
<option value="-3">-3
<option value="-2">-2
<option value="-1">-1
<option value="0">0
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<Label class="label2">Y: </Label>
<input type="text" id="2" name="param2" maxlength="15" class="input2" onKeyPress="validate(document.getElementById('2'))" onClick="SetPos(document.getElementById('2'))" required />
<Label class="label3">R: </Label>
<input type="radio" name="param3" value="1" CHECKED class="radiobut1"> <Label class="label4">1 </Label>
<input type="radio" name="param3" value="1.5" class="radiobut2"> <Label class="label5">1.5 </Label>
<input type="radio" name="param3" value="2" class="radiobut3"> <Label class="label6">2 </Label>
<input type="radio" name="param3" value="2.5" class="radiobut4"> <Label class="label7">2.5 </Label>
<input type="radio" name="param3" value="3" class="radiobut5"> <Label class="label8">3 </Label>
<input name="button1" class="button" type="submit" value="To check up" />
<BR><BR><BR><BR><BR><BR>
<HR color="#000000" width="100" align="center" >
<BR>
<BR>
</form>
</td>
</tr>
<tr>
<td bgcolor="#666666"><div align="right" >
</div></td>
</tr>
</table>
</body>
</html>
style.css:
root {
display: block;
}
.text1 {
background: #FFFFFF;
height: 20px;
}
.main_border {
border: 2px solid #000000;
position: absolute;
top: 20px;
left: 20px;
}
input {
background: #acacac;
color: #010101;
height: 20px;
border: 2px solid #111111;
font-size: 10px;
font-weight: bold;
vertical-align: top;
width: 120px;
}
.input1 {
position:absolute;
top: 210px;
left: 360px;
}
.input2 {
position:absolute;
top: 240px;
left: 360px;
}
.input3 {
position:absolute;
top: 270px;
left: 360px;
}
.label1 {
position:absolute;
top: 210px;
left: 330px;
}
.label2 {
position:absolute;
top: 240px;
left: 330px;
}
.label3 {
position:absolute;
top: 270px;
left: 330px;
}
.button {
/*padding: 15px 15px 5px 5px;*/
height: 20px;
width: 150px;
background: #acacca;
border-color: #000000;
font-size: 10px;
font-weight: bold;
color: #111111;
font-family: Arial,Helvetica,sans-serif;
position:absolute;
top: 310px;
left: 350px;
}
.p {font-family:Verdana; font-size:12px; margin:15px;}
.left {background-color:#CCCCCC; border-right:3px solid #424242; border-top:0px;}
.middle{
font-family: "Monotype Corsiva";
font-size: 14px;
color:#cccccc;
background-color: #000000;
}
body {background-image:url(img/bg.gif)}
Сервлет:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class First_servlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
} finally {
out.close();
}
}
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String sx = request.getParameter("param1");
String sy = request.getParameter("param2");
String sr = request.getParameter("param3");
Double x = Double.parseDouble(sx);
Double y = Double.parseDouble(sy);
Double r = Double.parseDouble(sr);
boolean state = isConObl(x, y, r);
String Result;
if (state){Result = "Point: X: "+x+" Y: "+y+" R: "+r+ " in area!!! ";}
else Result = "Point: X: "+x+" Y:"+y+" R: "+r+ " not in area!!! ";
writeFilePage(response, Result);
}
void writeFilePage(HttpServletResponse response, String msg) throws
java.io.IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(msg);
}
public boolean isConObl(double x, double y, double r)
{
boolean loc=false;
if ((y<=0 && y>=-r && x>=0 && x<= r) ||
(x>=0 && y>=0 && (r<=(Math.pow(Math.pow(x, 2)+Math.pow(y, 2),0.5)))) ||
(x<=0 && y>=0 && y<=2*x+r))
loc = true;
return loc;
}
}
Скриншот: