1

I could successfully connect to my website using my java class.

URLConnection myURLConnection=null; URL myURL=null; BufferedReader reader=null;

String mainUrl="https://example.com/ServCon/ServConI?"; 
StringBuilder sbPostData= new StringBuilder(mainUrl);        
sbPostData.append("page=").append(mpage);
mainUrl = sbPostData.toString();
try {
    //prepare connection
    myURL = new URL(mainUrl);
    myURLConnection = myURL.openConnection();
    myURLConnection.connect();
    
    reader= new BufferedReader(new  
    InputStreamReader(myURLConnection.getInputStream(),"UTF-8")); 
} catch(Exception e) {   
     System.out.println(e); 
}

But the problem is when I am trying to connect from jsp file using same java class then I am getting error:

e = (SSLHandshakeException) javax.net.ssl.SSLHandshakeException:     
sun.security.validator.ValidatorException: PKIX path building failed: 
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid 
certification path to requested target

I am using Glassfish 5.1.0 jdk 1.8.0_301 and apache Netbeans 12.5

  • [1] Do you get exactly the same result regardless of the browser used? [2] Update your question to detail your certificate configuration. [3] Review the many answers to these 2 questions which also relate to your **ValidatorException** and **SunCertPathBuilderException**: ["PKIX path building failed" and "unable to find valid certification path to requested target"](https://stackoverflow.com/q/21076179/2985643) and [Java: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target](https://stackoverflow.com/q/6908948/2985643) – skomisa Oct 23 '21 at 19:51
  • Also, there are dozens of questions and hundreds of answers on SO for the two exceptions you are getting. It would be helpful if you could update your question to provide more details on what you have already tried unsuccessfully. That helps others to focus only on the possible causes of your problem. – skomisa Oct 23 '21 at 19:58
  • I tried to import cert into trusted root certificates of web browser (I tried on different browsers including edge, chrome and firefox). While importing it does not give any error, it always prompt successfully imported. But it is not. When I tried to import by not selecting trusted root path but default path, then certificate is imported in the Other people tab. When I see into the Windows using certmgr then it shows me in the trusted root certificate. Inspite of that it is not showing in the Browsers trusted root certificate. Certificate is ok, there is no issue with that issued by cPanel. – ICL Sales EXIMON Oct 25 '21 at 07:14
  • Don't post additional information about your question in comments. Instead update the question itself. As it stands your question may be closed due to lack of details. – skomisa Oct 25 '21 at 16:53

1 Answers1

0

Well! I have have been struggling for last few days. Finally I could resolve the issue. The problem was Glassfish server. I replaced with Tomcat 9 server. But it want not working with that also. Then finally I realized that Tomcat 9 server need to be stop because NetBeans start at it on while executive web based project like jsp / servlet. It worked fine. Thanks