1

I have a ajax call that sends a value to the Servlet and Servlet creates a html file then returning the absolute path of the html file that has been created.
In response from the server is

"C:\Users\Ker\Documents\NETBEANS PROJECT\Titanium\build\web\default\result.html"

and in the ajax

 $(function() {
            $("#BTNRUN").click(function() {

                var html = $("#HTML").val();
                var body1 =html.replace('%','^');
                var body2=body1.replace('&','|');
                var css = $("#CSS").val();
                var js = $("#JS").val();
                var dataString = 'RUN=1&BODY=' + body2
                        + '&CSS=' + css + '&JS=' + js;
                $.ajax({
                    type: "POST",
                    url: "TitaniumServlet",
                    data: dataString,
                    success: function(data) {
                        window.open(data);
                    }
                });
                return false;
            });
        });

it opens a new browser but i alway go to about:blank page. is there something wrong with the adress?

edit:

try {

main_path is the context path of the project

        File file = new File(main_path + "\\result.html");
        if (file.createNewFile()) {
            System.out.println("File is created!");
        } else {
            System.out.println("File already exists.");
            file.delete();
            file.createNewFile();
        }
        writer = new PrintWriter(new FileOutputStream(file, false));
        writer.write(html codes here);
        return file.getAbsolutePath();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ProcessRun.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ProcessRun.class.getName()).log(Level.SEVERE, null, ex);
    }
Yagnesh Agola
  • 4,556
  • 6
  • 37
  • 50
the bosxcz
  • 91
  • 3
  • 13

1 Answers1

0

As per my understanding you have created your file and store on context path of your application. If your new created file is in context path than you can directly use relative path or context path to access your file your open it in new window using your server address.

Your servelet code include below line to get context path :

 //after your line writer.write(html codes here);  

String serverAddrs = request.getServerName()+":"+request.getServerPort();
String contextPath = "http://"+serverAddrs + main_path ;   
                                   //main_path  is your context path
contextPath = contextPath+"/result.html";
System.out.println(contextPath);  
return contextPath;  
Yagnesh Agola
  • 4,556
  • 6
  • 37
  • 50