求指点:我在eclipse里面编辑的一个jsp页面
编辑一个TransactionArrange.jsp页面,在表弟那里面输入预约的事务的相关信息,然后再建一个servlet类TransactionArrange.java,在里面将信息存入数据库(数据库里面存入这些信息:username,tel,email,date,resDate,responsible,reply),这是我编辑的页面,不知道是出了什么问题:
TransactionArrange.jsp
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
<table border=1>
<tr>
<td><font size=2>用户名:</font></td>
<td><Input type="text" name="username"></td>
</tr>
<tr>
<td><font size=2>电话:</font></td>
<td><Input type="text" name="tel"></td>
</tr>
<tr>
<td><font size=2>邮箱:</font></td>
<td><Input type="text" name="email"></td>
</tr>
<tr>
<td><font size=2>日期:</font></td>
<td><Input type="text" name="date"></td>
</tr>
<tr>
<td><font size=2>预约日期:</font></td>
<td><Input type="text" name="resdate"></td>
</tr>
<tr>
<td><font size=2> 事务:</font></td>
<td><Input type="text" name="responsible"></td>
</tr>
</table>
<BR>
<Input type="submit" name="b" value="注册">
</FORM>
</body>
</html>
TransactionArrange.java
package com.serv;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class TranactionArrange
*/
public class TransactionArrange extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public TransactionArrange() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out=response.getWriter();
String username=request.getParameter("username");
String tel=request.getParameter("tel");
String email =request.getParameter("email");
String contact=request.getParameter("tel");
String date=request.getParameter("date");
String resDate=request.getParameter("resDate");
String responsible=request.getParameter("responsible");
String beizhu=request.getParameter("beizhu");
if(username.length()==0)
{
response.sendRedirect("TransactionArrange.java");
}
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
String insertCondition="insert ReservationVALUES('"+username+"', '"+tel+"','"+email+"',"+date+",'"+resDate+"','"+responsible+"')";
String str="";
Connection con;
Statement sql;
catch(Exception e)
{
}
String uri="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=query";
con=DriverManager.getConnection(uri,"sa","sa");
sql=con.createStatement();
}
}
[解决办法]
在table前面没有看到form,
[解决办法]
同ls。。form里指定action
[解决办法]
在table前面添加form,
form里指定action是要跳转的路径
以下两种方式选择其一
form的method=“post”
或
java代码更改doGet方法如下
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}