还是关于servlet不能用的问题(50分)

  • 主题发起人 主题发起人 D影子D
  • 开始时间 开始时间
D

D影子D

Unregistered / Unconfirmed
GUEST, unregistred user!
运行出现让我下载的窗体!!!
是不是要配置web.xml??怎么配置???
我的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>
<!-- Define servlet-mapped and path-mapped example filters -->
<filter>
<filter-name>Servlet Mapped Filter</filter-name>
<filter-class>filters.ExampleFilter</filter-class>
<init-param>
<param-name>attribute</param-name>
<param-value>filters.ExampleFilter.SERVLET_MAPPED</param-value>
</init-param>
</filter>
<filter>
<filter-name>Path Mapped Filter</filter-name>
<filter-class>filters.ExampleFilter</filter-class>
<init-param>
<param-name>attribute</param-name>
<param-value>filters.ExampleFilter.PATH_MAPPED</param-value>
</init-param>
</filter>
<filter>
<filter-name>Request Dumper Filter</filter-name>
<filter-class>filters.RequestDumperFilter</filter-class>
</filter>
<!-- Example filter to set character encoding on each request -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>EUC_JP</param-value>
</init-param>
</filter>
<filter>
<filter-name>Compression Filter</filter-name>
<filter-class>compressionFilters.CompressionFilter</filter-class>
<init-param>
<param-name>compressionThreshold</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
</filter>
<!-- Define filter mappings for the defined filters -->
<filter-mapping>
<filter-name>Servlet Mapped Filter</filter-name>
<servlet-name>invoker</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>Path Mapped Filter</filter-name>
<url-pattern>/servlet/*</url-pattern>
</filter-mapping>

<!-- Example filter mapping to apply the "Set Character Encoding" filter
to *all* requests processed by this web application -->
<!--
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
<!--
<filter-mapping>
<filter-name>Compression Filter</filter-name>
<url-pattern>/CompressionTest</url-pattern>
</filter-mapping>
-->
<!--
<filter-mapping>
<filter-name>Request Dumper Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
<!-- Define example application events listeners -->
<listener>
<listener-class>listeners.ContextListener</listener-class>
</listener>
<listener>
<listener-class>listeners.SessionListener</listener-class>
</listener>
<!-- Define servlets that are included in the example application -->
<servlet>
<servlet-name>SendMailServlet</servlet-name>
<servlet-class>SendMailServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>
snoop
</servlet-name>
<servlet-class>
SnoopServlet
</servlet-class>
<!--
<init-param>
<param-name>foo</param-name>
<param-value>bar</param-value>
</init-param>
-->
<run-as>
<description>Security role for anonymous access</description>
<role-name>tomcat</role-name>
</run-as>
</servlet>
<servlet>
<servlet-name>
servletToJsp
</servlet-name>
<servlet-class>
servletToJsp
</servlet-class>
</servlet>
<servlet>
<servlet-name>
CompressionFilterTestServlet
</servlet-name>
<servlet-class>
compressionFilters.CompressionFilterTestServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
CompressionFilterTestServlet
</servlet-name>
<url-pattern>
/CompressionTest
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SendMailServlet</servlet-name>
<url-pattern>/SendMailServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
snoop
</servlet-name>
<url-pattern>
/snoop
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
servletToJsp
</servlet-name>
<url-pattern>
/servletToJsp
</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>
http://jakarta.apache.org/tomcat/debug-taglib
</taglib-uri>
<taglib-location>
/WEB-INF/jsp/debug-taglib.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>
http://jakarta.apache.org/tomcat/examples-taglib
</taglib-uri>
<taglib-location>
/WEB-INF/jsp/example-taglib.tld
</taglib-location>
</taglib>
<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/jsp/security/protected/*</url-pattern>
<!-- If you list http methods, only those methods are protected -->
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<!-- Anyone with one of the listed roles may access this area -->
<role-name>tomcat</role-name>
<role-name>role1</role-name>
</auth-constraint>
</security-constraint>
<!-- Default login configuration uses form-based authen
tication -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Example Form-Based Authen
tication Area</realm-name>
<form-login-config>
<form-login-page>/jsp/security/protected/login.jsp</form-login-page>
<form-error-page>/jsp/security/protected/error.jsp</form-error-page>
</form-login-config>
</login-config>
<!-- Environment entry examples -->
<!--env-entry>
<env-entry-description>
The maximum number of tax exemptions allowed to be set.
</env-entry-description>
<env-entry-name>maxExemptions</env-entry-name>
<env-entry-value>15</env-entry-value>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry-->
<env-entry>
<env-entry-name>minExemptions</env-entry-name>
<env-entry-value>1</env-entry-value>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>foo/name1</env-entry-name>
<env-entry-value>value1</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>foo/bar/name2</env-entry-name>
<env-entry-value>true</env-entry-value>
<env-entry-type>java.lang.Boolean</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>name3</env-entry-name>
<env-entry-value>1</env-entry-value>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>foo/name4</env-entry-name>
<env-entry-value>10</env-entry-value>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
<!-- EJB Reference -->
<ejb-ref>
<description>Example EJB Reference</description>
<ejb-ref-name>ejb/Account</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.mycompany.mypackage.AccountHome</home>
<remote>com.mycompany.mypackage.Account</remote>
</ejb-ref>
<!-- Local EJB Reference -->
<ejb-local-ref>
<description>Exampl
e Local EJB Reference</description>
<ejb-ref-name>ejb/ProcessOrder</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.mycompany.mypackage.ProcessOrderHome</local-home>
<local>com.mycompany.mypackage.ProcessOrder</local>
</ejb-local-ref>

</web-app>

 
有没有人帮我?
开始我的servlet可以运行,可是有乱码(中文),所以我加了
setContentype(。。。)就出现让我下载或运行的对话框了,为什么?
怎么做?
 
你的setContentype是怎么写的?
我想实现下载效果还没有能够成功呢:(
这样:
request.setCharacterEncoding("GB2312");//设置为中文编码
 
对阿,我就是加的那句话!
不加的话是下面的效果
http://202.205.177.236:8080/Test.class
漱壕.% ()VCodeLineNumberTabledoGetR(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V Exceptions SourceFile Test.java A
This is a servlet test.濂界殑!
! "# $ Test/Testjavax/servlet/http/HttpServletjavax/servlet/ServletExceptionjava/io/IOException&amp;javax/servlet/http/HttpServletResponse getWriter()Ljava/io/PrintWriter;java/io/PrintWriterprintln(Ljava/lang/String;)Vflush! * 6,N--
 

执行应该是:http://202.205.177.236:8080/Test
吧?
还有,正常的servlet映射应该是这样的:
上半部分是servlet名字和class文件的映射,
beanservlettest.Servlettest是指beanservlettest.Servlettest.calss文件。
下半部分是servlet名字和URL的映射。
下面是例子:
<servlet>
<servlet-name>servlettest</servlet-name>
<servlet-class>beanservlettest.Servlettest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>appt</servlet-name>
<url-pattern>/appt</url-pattern>
</servlet-mapping>
而且我看你贴出的web.xml不是你自己写的吧???
 
可能是我放的目录不对,我放在C:/tomcat/webapps/ROOT下面了
但是可以执行阿,为什么加了
request.setCharacterEncoding("GB2312");就不行了呢??
我是第一次这么用,以前用jbuilder都不用管
 
放在C:/tomcat/webapps/ROOT还可以执行???
哦,我明白了,你那不是执行,可能只是浏览器把她当作txt直接打开了而已。
(你用记事本打开你的Test.class看看)
用Jbuilder是因为它帮你把一切都打点妥当了,
现在你自己写,当然是要注意配置文件,目录的设置之类,
这些都要自己动手写。
Test.class应该放在。
C:/tomcat/webapps/ROOT/WEB-INF/classes/yourpackage/Test.class(假如你的Test.java里写的是package yourpackage).
然后在
C:/tomcat/webapps/ROOT/WEB-INF/web.xml里添加下面的东西:
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>yourpackage.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
以上操作过程严格注意 字母的大小写。
ps:不是没有人帮你,我昨天下午就看了你的问题,但是不明白你的意思。
你既不把代码贴出来,也不把自己的操作过程讲述一下。
很难猜出错误原因的:(
 
呵呵,谢谢你了。
以后还要多请教你呢!
 
后退
顶部