out.println("href=")的问题
Exservlet写信息进数据库后,想有个连接返回到主页面(index.html),但是直接写out.println( " <a href= '/wy/index.html '> " + "renturn "+ " </a> " );好像不行,这样写的实际连接是http://127.0.0.1:8080/wy/servlet/index.html。怎么才能让连接到我想要的index.html?
×××××××××××××××××
目录结构是这样的:
C:\tomcat\webapps\wy\WEB-INF\classes\myservlet\Exservlet.class
\index.html\
×××××××××××××××××
Exservlet文件
×××××××××××××××××
package myservlet;
import java.io.*;
import
javax.servlet.ServletException;
import javax.servlet.http.*;
import java.sql.*;
import com.jspdev.ch12.*;
import com.jspdev.util.*;
public class ExServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
response.setContentType( "text/html;charset=gb2312 ");
PrintWriter out = response.getWriter();
String productId=request.getParameter( "productId ");
String name=request.getParameter( "name ");
String price=request.getParameter( "price ");
String producer=request.getParameter( "producer ");
String descn=request.getParameter( "description ");
String categoryId=request.getParameter( "categoryId ");
//下面三步将界面的值传入到Bean中
Product lbean=new Product();
lbean.setProductId(productId);
lbean.setPrice(price);
lbean.setCategoryId(categoryId);
lbean.setName(name);
lbean.setDescription(descn);
lbean.setProducer(producer);
//下面的这个步为连接数据库
try{
//下面为写入数据库
ProductBean aduB=new ProductBean();
aduB.addProduct(lbean);
out.println( " <html> ");
out.println( " <head> <title> addRecord </title> </head> ");
out.println( " <body> ");
out.println( " <p> Add Success </p> ");
out.println( " <a href= '/wy/index.html '> " + "renturn "+ " </a> " );
out.println( " </body> </html> ");
}catch(Exception e){
e.printStackTrace();
}
}
public void destroy() {
super.destroy();
}
}
------解决方案--------------------试试 out.println( " <a href=\ "/wy/index.html\ "> return </a> ");