JSP跳转到JSP404错误 谁能帮我看看··
欢迎页面:<formname="form1"action="SaveFirstLevelTitle.jsp"method="post">标题名: <inputt...
欢迎页面:<form name="form1" action="SaveFirstLevelTitle.jsp" method="post">
标题名: <input type="text" name="titleName"><br>
<input type=submit value=提交>
<input type="reset" value=重置><br>
</form>
SaveFirstLevelTitle.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="ch06.*" %>
<%@ page import="ch02.*" %>
<html>
<head>
<title>My JSP 'SaveFirstLevelTitle.jsp' starting page</title>
</head>
<body>
<%
request.setCharacterEncoding("GBK");
System.out.println("123");
String titlename = request.getParameter("titleName");
FirstLevelTitle fTitle = new FirstLevelTitle();
fTitle.setTitleName(titlename);
fTitle.setCreator("管理员");
FirstLevelTitleDbOperation db = new FirstLevelTitleDbOperation();
int result = db.insertOneRecord(fTitle);
if(result>0){
request.getRequestDispatcher("success.jsp").forward(request,response);
}else{
request.getRequestDispatcher("error.jsp").forward(request,response);
}
%>
</body>
</html>
package ch06;
FirstLevelTitleDbOperation.java:
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import ch02.FirstLevelTitle;
import ch03.ConnectionManager;
public class FirstLevelTitleDbOperation {
public int insertOneRecord(FirstLevelTitle fTitle){
int result = 0;
Connection con = null;
PreparedStatement ps = null;
try{
con = ConnectionManager.getConnection();
String strSql = "insert into FirstLevelTitle values(?,?,?)";
ps = con.prepareStatement(strSql);
ps.setInt(1,getNewsId());
ps.setString(2, fTitle.getTitleName());
ps.setString(3, fTitle.getCreator());
result = ps.executeUpdate();
}catch(SQLException sqlE){
sqlE.printStackTrace();
}finally{
ConnectionManager.closeStatement(ps);
ConnectionManager.closeConnection(con);
}
return result;
}
public int getNewsId(){
int id = 0;
Connection con = null;
PreparedStatement ps = null;
ResultSet res = null;
//System.out.println("这里出错啦!");
try{
con = ConnectionManager.getConnection();
String strsql = "select max(id) from FirstLevelTitle";
ps = con.prepareStatement(strsql);
res = ps.executeQuery();
if(res.next()){
id = res.getInt(1);
}
}catch(SQLException sqlE){
sqlE.printStackTrace();
}finally{
ConnectionManager.closeStatement(ps);
ConnectionManager.closeConnection(con);
}
return id+1;
}
} 展开
标题名: <input type="text" name="titleName"><br>
<input type=submit value=提交>
<input type="reset" value=重置><br>
</form>
SaveFirstLevelTitle.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="ch06.*" %>
<%@ page import="ch02.*" %>
<html>
<head>
<title>My JSP 'SaveFirstLevelTitle.jsp' starting page</title>
</head>
<body>
<%
request.setCharacterEncoding("GBK");
System.out.println("123");
String titlename = request.getParameter("titleName");
FirstLevelTitle fTitle = new FirstLevelTitle();
fTitle.setTitleName(titlename);
fTitle.setCreator("管理员");
FirstLevelTitleDbOperation db = new FirstLevelTitleDbOperation();
int result = db.insertOneRecord(fTitle);
if(result>0){
request.getRequestDispatcher("success.jsp").forward(request,response);
}else{
request.getRequestDispatcher("error.jsp").forward(request,response);
}
%>
</body>
</html>
package ch06;
FirstLevelTitleDbOperation.java:
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import ch02.FirstLevelTitle;
import ch03.ConnectionManager;
public class FirstLevelTitleDbOperation {
public int insertOneRecord(FirstLevelTitle fTitle){
int result = 0;
Connection con = null;
PreparedStatement ps = null;
try{
con = ConnectionManager.getConnection();
String strSql = "insert into FirstLevelTitle values(?,?,?)";
ps = con.prepareStatement(strSql);
ps.setInt(1,getNewsId());
ps.setString(2, fTitle.getTitleName());
ps.setString(3, fTitle.getCreator());
result = ps.executeUpdate();
}catch(SQLException sqlE){
sqlE.printStackTrace();
}finally{
ConnectionManager.closeStatement(ps);
ConnectionManager.closeConnection(con);
}
return result;
}
public int getNewsId(){
int id = 0;
Connection con = null;
PreparedStatement ps = null;
ResultSet res = null;
//System.out.println("这里出错啦!");
try{
con = ConnectionManager.getConnection();
String strsql = "select max(id) from FirstLevelTitle";
ps = con.prepareStatement(strsql);
res = ps.executeQuery();
if(res.next()){
id = res.getInt(1);
}
}catch(SQLException sqlE){
sqlE.printStackTrace();
}finally{
ConnectionManager.closeStatement(ps);
ConnectionManager.closeConnection(con);
}
return id+1;
}
} 展开
3个回答
展开全部
你的欢迎页和SaveFirstLevelTitle.jsp不在同一目录吧?
最简单的方法就是把两个JSP放到同一目录,
要不就在你的欢迎页上<form name="form1" action="SaveFirstLevelTitle.jsp" method="post">中的action追加路径。
最简单的方法就是把两个JSP放到同一目录,
要不就在你的欢迎页上<form name="form1" action="SaveFirstLevelTitle.jsp" method="post">中的action追加路径。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
重启下服务器撒。可能文件没上传上去
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询