servlet的执行(50分)

  • 主题发起人 主题发起人 jerjoan
  • 开始时间 开始时间
J

jerjoan

Unregistered / Unconfirmed
GUEST, unregistred user!
我遇到了一点问题,想向诸位大侠请教:
我写了一个小的Servlet 小程序, 内容如下
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;
public class RequestHeaderExample extends HttpServlet{
public voiddo
Get(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out= res.getWriter();
Enumeration e = req.getHeaderNames();
while(e.hasMoreElements()){
String name = (String)e.nextElement();
String value= req.getHeader(name);
out.println(name + "=" + value);
}
}
}
编译通过,可通过tomcat 访问生成的class文件时, 却出现询问是否下载这个class文件的窗口, 不知道是什么原因.
如果不影响你工作的话,请帮我看看是怎么回事,谢谢!
 
Tomcat上发布Servlet时候,需要对其下的XML文件,进行配置,是否没有配置对
 
能否指点一下,要怎么配.
 
在你的应用程序路径的web-inf下,建议一个web.xml添加以下代码
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
 
能解释一下,上面各句话的函意吗?
 
web.xml可如下配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>RequestHeaderExample</servlet-name>
<servlet-class>RequestHeaderExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestHeaderExample</servlet-name>
<url-pattern>/RequestHeaderExample</url-pattern>
</servlet-mapping>
</web-app>
其中标记servlet-name中是servlet的别名,<servlet-class>中是类的名字,一般这两者定义成一样。
<url-pattern>定义了引用模式,即在默认目录下怎么用。
 
这里面有两个显示方法
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
<web-app>
<display-name>My Web</display-name>
<servlet>
<servlet-name>RequestHeaderExample</servlet-name>
<servlet-class>RequestHeaderExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestHeaderExample</servlet-name>
<url-pattern>/RequestHeaderExample</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
</web-app>
http://localhost:****/apphome/RequestHeaderExample或者http://localhost:****/apphome/servlet/RequestHeaderExample
 
你得配置服务器,通过服务器编译啊,在tomcat目录下的bin目录,点startup,然后就可以了
 
下面该怎么实现:
如何弹出一个提示框
如何定义一个"退出"铵钮,点击后关闭窗口.
 
没有做servlet的配置文件
web.xml文件
<servlet>
<servlet-name>DownDzsbInf</servlet-name>
<servlet-class>PuDong.Huabo.Web.Dzsb.DownDzsbInf</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DownDzsbInf</servlet-name>
<url-pattern>/Dzsb/DownDzsbInf</url-pattern> <!--在这里写明你的访问路径-->
</servlet-mapping>
做个按钮 代码如下
<input type="button" value="退出" name="close" onclick="javascript:if(confirm('确实退出吗?')===true) return window.close();
else
return false ">
 
我写了一个html文件脚本如下:
<html>
<head>
<title>Untitleddo
cument</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<frameset rows="80,*" cols="*" frameborder="NO" border="0" framespacing="0">
<frame src="top.jsp" name="topFrame" scrolling="NO" noresize >
<frameset cols="80,*" frameborder="NO" border="0" framespacing="0">
<frame src="left.jsp" name="leftFrame" scrolling="NO" noresize>
<frame src="mainArea.jsp" name="mainFrame">
</frameset>
</frameset>
<noframes><body>
Hello everybody!!
</body></noframes>
</html>
直接双击文件,可以正常显示,可是放到tomcat下就会报错。不知道这是什么原因。
 
朱界面分成三块,分别显示如下错误:
A Servlet Exception Has Occurred
org.apache.jasper.JasperException: Unsupported encoding:
at org.apache.jasper.compiler.ParserController.getReader(ParserController.java:451)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:213)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:220)
at org.apache.jasper.servlet.JspServlet.doLoadJSP(JspServlet.java:478)
at org.apache.jasper.servlet.JasperLoader12.loadJSP(JasperLoader12.java:146)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:449)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:159)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:171)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:328)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:407)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:251)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:196)
at org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
at org.apache.catalina.authen
ticator.Authen
ticatorBase.invoke(Authen
ticatorBase.java:464)
at org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:242)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:975)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2041)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:414)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:975)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:159)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:818)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:897)
at java.lang.Thread.run(Thread.java:536)
 
不好意思,是我frame装入的jsp文件有问题。污了大家的眼,惭愧,惭愧!!
 
后退
顶部