我想在java中构建一个Web应用程序,但找不到将我的html链接到java的方法
答案 0 :(得分:0)
您可以使用response.sendRedirect
:
response.sendRedirect("localhost/yourlink");
或:
response.sendRedirect("http://stackoverflow.com");
答案 1 :(得分:0)
您可以将表单放到您的html页面并为其提供serlet url模式,如下所示:
//drawing hexagons
var grid;
var numColumns;
var numRows;
var radius;
var diameter;
var pallet = {123, 244, 321, 342, 783};
function setup(){
var createCanvas(1440, 900);
canvas.parent("sketch-holder");
canvas.id("background-canvas");
smooth();
radius = 15;
diameter = radius * 2;
numColumns = width / (sqrt(3) * radius) + 1;
numRows = height / (.75 * diameter) + 1;
grid = new Grid(numColumns, numRows, radius);
for(var i = 0; i < numColumns; i++){
for(var j = 0; j < numRows; j++){
var/*Hexagon*/ selected = grid.getHexagon(i, j);
selected.setFillColor(pallet[random(5)]);
}
}
grid.draw();
frameRate(60);
}
function draw(){
grid.draw();
for(var i = 0; i < 15; i++){
var/*Hexagon*/ selected = grid.getHexagon(random(numColumns), random(numRows));
selected.setFillColor(pallet[random(5)]);
}
}
class Hexagon{
var c;
var r;
var x;
var y;
var angle = TWO_PI / 6;
var startAngle = PI / 6;
constructor(center, radius){
this.r = radius;
this.x = center[0];
this.y = center[1];
}
function draw(){
//noStroke();
fill(c);
vertY = new Array(6);
vertX = new Array(6);
for(var i = 0; i < 6; i++){
angleRad = (angle * i) + startAngle;
vertX[i] = x + (r * cos(angleRad));
vertY[i] = y + (r * sin(angleRad));
}
beginShape();
vertex(vertX[0], vertY[0]);
vertex(vertX[1], vertY[1]);
vertex(vertX[2], vertY[2]);
vertex(vertX[3], vertY[3]);
vertex(vertX[4], vertY[4]);
vertex(vertX[5], vertY[5]);
endShape(CLOSE);
}
function setFillColor(color setColor){
c = setColor;
}
}
class Grid{
var columns;
var rows;
var r;
var hexagons = new Array[][];
constructor(numColumns, numRows, radius){
this.columns = numColumns;
this.rows = numRows;
this.r = radius;
var hexagons = new Array[columns][rows];
var center = {0, 0};
for(var i = 0; i < rows; i++){
for(var j = 0; j < columns; j++){
hexagons[j][i] = new Hexagon(center, r);
center[0] += (r * sqrt(3));
}
center[1] += (r * 3) / 2;
if(i % 2 == 0){
center[0] = (sqrt(3) / 2) * r;
}else{
center[0] = 0;
}
}
}
function draw(){
for(var i = 0; i < rows; i++){
for(var j = 0; j < columns; j++){
hexagons[j][i].draw();
}
}
}
function getHexagon(column, row){
return hexagons[column][row];
}
}
服务器端web.xml
<form action="/servlet_url_pattren">
...
</form>