我创建了一个编辑数据库的Web应用程序......
我想知道在点击提交后如何添加或重定向页面。
抱歉,我还在学习......
目前我使用“usebean”将表单内容插入数据库。我想知道如何在字段中输入所有信息后重定向页面,然后单击提交..
由于
这是代码:
<%@ page language="Java" import="java.sql.*" %>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<html>
<head><title>CSN Survey</title></head>
<body bgcolor="#ffffff">
<div>
<img id="title" src="images/CSN.gif" width="243" height="27" alt="CSN"/>
<img id="logo" src="images/tr_logo_40.gif" width="178" height="40" alt="tr_logo_40"/>
</div>
<hr>
<h1> insert comment </h1>
<div id="container">
<form action="" name="form1" method="POST">
<br>
<br>
<br>
<td><br>Write your comment here:</td>
<div id="q1"
<td>id:<%=request.getParameter("id")%></td>
<td>First name:<textarea name="first_name" rows="1" cols="10"></textarea></td>
<td>Last name:<textarea name="last_name" rows="1" cols="10"></textarea></td>
<br>
<br>
</div>
<td>
<input type = "submit" value="Submit">
</td>
</form>
</div>
<jsp:useBean id="survey" class="csnsurveysource.csnsurveyclass" scope="page">
<jsp:setProperty name="survey" property="*"/>
</jsp:useBean>
<% survey.insert();%>
</body>
</html>
csnsurveyclass.java :
package csnsurveysource;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
public class csnsurveyclass
{
private int id;
private String first_name;
private String last_name;
private Connection connection=null;
private ResultSet rs = null;
private Statement st = null;
String connectionURL = "jdbc:postgresql://localhost:5432/test";
public csnsurveyclass()
{
try {
// Load the database driver
Class.forName("org.postgresql.Driver");
// Get a Connection to the database
connection = DriverManager.getConnection(connectionURL, "postgres", "qqQQ11!!");
}catch(Exception e){
System.out.println("Exception is ;"+e);
}
}
public void setid(int id)
{
this.id = id;
}
public int getid()
{
return (this.id);
}
public void setfirst_name(String first_name)
{
this.first_name = first_name;
}
public String getfirst_name()
{
return (this.first_name);
}
public void setlast_name(String last_name)
{
this.last_name = last_name;
}
public String getlast_name()
{
return (this.last_name);
}
public void insert()
{
try
{
String sql = "update testing set fname = '"+first_name+"',lname = '"+last_name+"' where id = "+id+"";
Statement s = connection.createStatement();
s.executeUpdate (sql);
s.close ();
}
catch(Exception e){
System.out.println("Exception is ;"+e);
}
}
}
答案 0 :(得分:2)
答案 1 :(得分:1)
将您要重定向的位置放在表单标记内的操作中
<form action="put here ur action/url" name="form1" method="POST">