我想从servlet跳转到html,并且传递参数给html,能实现吗?

 我来答
匿名用户
2013-10-23
展开全部
html静态页面是不能接收参数的,你可以把html页面改为jsp页面,实现如下servlet类package one.two;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class Servlet extends HttpServlet {
public Servlet() {
super();
}/** 好网 : http://www.ablanxue.com
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost( request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {request.setAttribute("param"," http://www.ablanxue.com");
RequestDispatcher requestDispatcher=request.getRequestDispatcher("/ablanxue.jsp");
requestDispatcher.forward(request,response);

} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}}
jsp页面接收参数 ablanxue.jsp代码如下<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'ablanxue.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>

<body>

<%
String PAR=(String)request.getAttribute("param");
%>
上面这个PAR就是得到的参数了;输入出
<%=PAR%>
页面会输出 : http://www.ablanxue.com

<br>
</body>
</html>
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式