如何在打开html页面是调用servlet? 不好意思,我也是刚开始学习,只知道通过bean调用参数,这个就不明白了,关注!顶! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是这样的,我用的是tomcat4.1.12我知道在shtml文件中调用,我的test.shtml文件放在C:\tomcat\webapps\examples目录下,servlet类文件放在C:\tomcat\webapps\examples\WEB-INF\classes\project目录下,test.shtml的代码如下:<html><head><title>Java Servlet Sample - CompanyUser</title></head><body><servlet code=project.CompanyUser><param name=Company1 value=hello></servlet></body></html>结果无法调用,我想是我的code写错了,应该如何写才行?请高手指点! study_body,大侠,你指什么?我是servlet,不是jsp啊 使用JAVASCRIPT自动提交HTML的表单,action指向你的servlet,然后再由你的servlet调用你的index.html同时也可以传递参数。 将index.html改成index.jsp不就是jsp了吗? index.html-------------------------<span id="a"></span><iframe src="/servlet/myServlet" hspace="0" vspace="0" width="0" height="0" scrolling="no" frameborder="0"></iframe>---------------------------myServlet------------------import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class myServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html;charset=gb2312"); request.setCharacterEncoding("GB2312"); PrintWriter out = response.getWriter(); String s=""; s+="<html>"; s+="<head>"; s+="<title>test</title>"; s+="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">"; s+="</head>"; s+="<body>"; s+="<h1>test</h1>"; s+="</body>"; s+="</html>"; out.println("<script>parent.a.innerHTML='"+s+"';</script>"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request,response); }}---------------------编译,在浏览器输入http://localhost:8080/index.html我这里测试通过!ok??? beyond_xiruo大侠,如果是写成Server-Side Includes怎么写,就象我上面写的那种的? beyond_xiruo大哥.我按你的方法运行了,还是不行src="/servlet/myServlet"是通过什么指定的啊? 在你放入tomcat 时,应修改你的web-inf 目录的web.xml.可C:\tomcat\webapps\examples\WEB-INF参考目录中web.xml. 我输入的地址是src="http://192.168.0.78:8080/examples/servlet/myServlet",最开始几次运行成功了,可后来有出错了,说网页有错误,详细信息是:没有权限,URL: http://192.168.0.78:8080/examples/servlet/myServlet struts2如何清空类似struts1中的formbean 菜鸟问页面显示问题 急急急!!!操作CLOB数据没插进去怎么回事? java实现剪切,复制,粘贴功能 放到jsp页面中,OBJECT 这样最大化页面为什么不起作用 关于out.println的问题 tomcat怎么不支持中文呢? 我画的表格,为什么列的宽度会随着列内容的长短而自动变化? 不容易的问题,就请高手进来领100分吧! 为什么我在javascript用close()关闭窗口的时候,总有这样的提示 巨人之间的对话:Sun VS Microsoft java的中文API函数指南
<html>
<head>
<title>Java Servlet Sample - CompanyUser</title>
</head>
<body>
<servlet
code=project.CompanyUser>
<param name=Company1 value=hello>
</servlet>
</body>
</html>
结果无法调用,我想是我的code写错了,应该如何写才行?请高手指点!
-------------------------
<span id="a"></span>
<iframe src="/servlet/myServlet" hspace="0" vspace="0" width="0" height="0" scrolling="no" frameborder="0"></iframe>
---------------------------
myServlet
------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;public class myServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("GB2312");
PrintWriter out = response.getWriter();
String s="";
s+="<html>";
s+="<head>";
s+="<title>test</title>";
s+="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">";
s+="</head>";
s+="<body>";
s+="<h1>test</h1>";
s+="</body>";
s+="</html>";
out.println("<script>parent.a.innerHTML='"+s+"';</script>");
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
doGet(request,response);
}
}
---------------------
编译,在浏览器输入http://localhost:8080/index.html
我这里测试通过!
ok???
可C:\tomcat\webapps\examples\WEB-INF参考目录中web.xml.