发布之后点击运行按钮,看到的是.application文件的xml内容,查阅msdn后发现.application文件应该定义mime类型为:application/x-ms-application

因为主机是虚拟主机,不具备修改mime映射的权限,因此自己写servlet,映射到*.application文件。

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class MapMime4Application extends HttpServlet {
    
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path 
= request.getServletPath();
        path 
= this.getServletContext().getRealPath(path);
        File file 
= new File(path);
        
if (!file.exists()){
            response.setStatus(
404);
            
return;
        }

        response.setContentType(
"application/x-ms-application");
        FileInputStream stream 
= null;
        
try {
            stream 
= new FileInputStream(file);
            
byte[] buf = new byte[(int) file.length()];
            stream.read(buf);
            response.getOutputStream().write(buf);
        }
 finally{
            
if(stream != null{
                
try {
                    stream.close();
                }
 catch (Exception e) {
                }
                
            }

        }
        
    }

}


修改web.xml, 增加:
   <servlet>
      
<servlet-name>MapMime4Application</servlet-name>
      
<servlet-class>MapMime4Application</servlet-class>
    
</servlet>
  
<servlet-mapping>

    
<servlet-name>MapMime4Application</servlet-name>
    
<url-pattern>*.application</url-pattern>
  
</servlet-mapping>

修改后ClickOnce可以正常安装执行 :)
posted on 2006-01-12 15:45  steeven  阅读(2167)  评论(6编辑  收藏  举报