out.println("href=")的问题

ocean1004 2007-06-11 12:12:58
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();
}
}
...全文
189 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
function_chk 2007-06-11
  • 打赏
  • 举报
回复
试试 out.println("<a href=\"/wy/index.html\">return</a>");
ocean1004 2007-06-11
  • 打赏
  • 举报
回复
成功了,谢谢你~~~

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧