请教大家一个问题,我的项目用到Tomcat6,在前一阶段工作中,已完成部分可以正常运行。现在老板要求将参数直接使用URL传递,根据我的认识,这类请求将直接通过GET方法被处理。
所以我在代码里对doGet方法做了相应修改。但是当我运行程序时,输入URL如下:
 http://localhost:8080/service_name?parameter=xxxx
其中service_name是我的服务名称,parameter为所需名参,xxx是实参。但是接下来只是弹出一个对话框,要我下载一个与我的服务同名的文件。
之后我输入如下URL:
http://localhost:8080/service_name/service_name?parameter=xxxx出现同样问题,如我输入与未修改时同样的URL,如:http://localhost:8080/service_name,该URL会被自动转为:
http://localhost:8080/service_name/?parameter=xxxx,然后跳出同样对话框.
我想应该是我的配置文件有问题,因为Tomcat是正常运行的。请问各位,对于这种URL带参的应用,Tomcat的配置是否是不变的还是需要作出调整?

解决方案 »

  1.   

    <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" URIEncoding="utf-8" />在你的Tomcat的配置文件server.xml中加上:URIEncoding="utf-8" 试试
      

  2.   

    thanks to #1, but it doesn't work.
      

  3.   

    http://localhost:8080/ 后面应该跟的是项目名吧 
    http://localhost:8080/项目名/servlet名?参数=""
    但是这样的话 传中文有肯能会出乱码 设置个过滤器 处理乱码吧 或者根据2楼的 直接改配置文件
    建议还是设过滤器
      

  4.   

    Hi, there, i don't need to transport the chinese parameter, all in english. I didn't describe the problem clearly. The project name is "mytree" and the servlet class file is "TreeServer.class", so if the servlet is invoked, the url should be as "http://localhost:8080/mytree" without parameter, and it does work correctly. 
    Now the new requirement is add a parameter named "session", so, generally the url should be like "http://localhost:8080/mytree/mytree?session=parameter_value", right? if so, when execute, a download dialogue will be given. So, should I change the url to "http://localhost:8080/mytree/TreeServer?session=parameter_value" ? Thanks for your help.
      

  5.   

    sorry to all, My office is not in china. So I can just input english, when I at home, I can sure input chinese. So, shall we just focus on the questions? :-) Thanks.
      

  6.   

    HttpServletRespones  respones.setContentType("text/html");写的是否有无。
      

  7.   


    很艰难的看懂了你的话 你将url换成http://localhost:8080/mytree/TreeServer?session=parameter_value 有用没?第一种应该不是的 你这个有用没的
      

  8.   


    这个应该没关系吧 他是访问服务端的servlet 对象 response是返回客户端的数据所用到的
      

  9.   

    1.楼主你可以把你的代码贴出来吗,如果说是用servlet的话,你在使用GET 的时候,可以带上参数的..HTTP://localhost:8080/mytree/ServletName?XXXX...
    2.你在jsp提交button中的action是你的servlet,然后在后面使用GET的method..这样你就可以在你的URL里面带上你的参数..
      

  10.   

    to 8楼: 我觉得与response无关,这个和输出没有关系吧。
    to 9楼:如果我用类似于
            http://localhost:8080/mytree/TreeServer?session=parameter_value 
    的URL,tomcat会直接返回服务不可用/无法找到服务的页面。现在我自己的问题是,如果url为http://localhost:8080/mytree/mytree?session=parameter_value,session参数可以被servlet得到,并且servlet端的服务可以正常运行(在我的程序里为从数据库中读取数据),但是接下来所有被读取得数据却无法传送给相对应的applet。 在applet端里所用的读取url的方法为
      url urlServlet=new url(getCodebase(),"tree");
    接下来通过这个创建的urlServlet打开连接(openConnection())并创建输入输出流,以与Servlet通信
    根据程序的运行情况,我的分析是,urlServlet对象不能正确的解析servlet的url,以至于无法正常通信。原因是如果我输入的URL是: http://localhost:8080/mytree/,因为我在servlet端设置了一个默认session值为4,那么两端的运行都正常!那么,两者间运行的差异就在于如何在URL后加上参数名(session)及其值。不知道有没有那位兄弟或姐妹有相应的经验? 多谢!另外:我现在不在办公室里,所以我无法贴出代码。
      

  11.   

    no one knows about it?
      

  12.   

    怀疑就是contentType设错了算我没说,,,
      

  13.   

    to different contentType ,the browser can performance differently,maybe render,maybe download....
      

  14.   

    if the conttenttype is set error,the action is download maybe....
      

  15.   

    Thanks to all the participant. The problem is gone. I thought the source might be the configuration of the input-, and outputstream on both side or/and maybe the definition of the servlet URL. Anyway, later I will write down the whole things in my blog. Thank you all again.