<%
String path=requst.getContextPath();
String basePath=requst.getScheme()+”://”+requst.getServerName()”:”+requst.getServerPort()+path+”/”;
%>
1.在标签中有
”>
这是标准路径,在后面的连接的基本路径就是它
2.在MyEclipse下的JSP页面中右击,选择属性在JSP中更改编码为GB18030以后默认的编码就是这个了!就不用再做修改了!
3.
<%
String strId = request.getParameter(“id”);
if(strId = = null || strId.trim().equals(“”))
{ out.println(“Error ID!”);
Return;
} 这两个条件不能调换,因为必须保证它不是空才能.trim()它,否则会出现空指针异常
int id =0;
try
{
id = Integer.parseInt(strId);
} catch (NumberFormatException e)
{
out.println(“Error id again!”);
return;
}
%>
4.在eclipse中有个snippets,里面是许多
程序代码,可以用
5.用javascript自动跳转
3秒钟之后自动跳转,如果不跳转,请点击下面链接
JSP”>主题
列表 xml:namespace prefix = span id = “time” style=”background />
3秒钟之后自动跳转,如果不跳转,请点击下面链接
6.提交到自己的页面
<%
request.setCharacterEncoding("GBK");
String action = request.getParameter("action");
if (action != null &;&; action.trim().equals("post")) { 这是判断提交的标志
String title = request.getParameter("title");
System.out.println(title);
String cont = request.getParameter("cont");
System.out.println(cont);
Connection conn = DB.getConn();
boolean autoCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
int rootId = -1;
String sql = "insert into article values (null, ?, ?, ?, ?, now(), ?)";
PreparedStatement pstmt = DB.prepareStmt(conn, sql, Statement.RETURN_GENERATED_KEYS);
pstmt.setInt(1, 0);
pstmt.setInt(2, rootId);
pstmt.setString(3, title);
pstmt.setString(4, cont);
pstmt.setInt(5, 0);
pstmt.executeUpdate();
ResultSet rsKey = pstmt.getGeneratedKeys();
rsKey.next();
rootId = rsKey.getInt(1);
Statement stmt = DB.createStmt(conn);
stmt.executeUpdate("update article set rootid = " + rootId + " wh
ere id = " + rootId);
connmit();
conn.setAutoCommit(autoCommit);
DB.close(pstmt);
DB.close(stmt);
DB.close(conn);
response.sendRedirect("article.jsp");
}
%>
7.DB.java
package com.bjsxt.bbs;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public c