aspose file tools*
The moose likes JSP and the fly likes how to convert a .jsp to a .java/.class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to convert a .jsp to a .java/.class file" Watch "how to convert a .jsp to a .java/.class file" New topic
Author

how to convert a .jsp to a .java/.class file

jerry cowell
Greenhorn

Joined: Apr 29, 2010
Posts: 7
Hi java/jsp experts, i don't know java/jsp, so please help me out. I want to convert a .jsp to a .java/.class file. is there a tool available, please let me know if you have any pointers.... or can i do it manually: these are a few lines that the .jsp contains, and i would like to translate this to be in .java/.class format:

<%@ page import="sun.misc.BASE64Encoder, javax.crypto., javax.crypto.spec."%>
<%@ page import="java.util.StringTokenizer" %>
<%@ page import="java.util.Map" %>
<%! ....... .......
sb.append("<input type=\"hidden\" name=\"orderPage_serialNumber\" value=\"");
sb.append(serialNumber);
sb.append("\">\n");
return sb.toString();
....... ....... %>
how can i translate the above import statements and html elements from jsp to java, please let me know. Once i have the .java file created from the .jsp, I will compile .java to create the .class file and invoke the .class from an ERP program. please help. Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Steps:
  • Open a text editor or IDE.
  • Create a Java class.
  • Cut and paste the Java from the JSP into the new class.
  • Delete the ridicluous JSP file.


  • In other words, using a JSP for this is nonsensical.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61612
        
      67

    "jerry the rancher", you have changed your display name from one that is valid, to one that is not. Please restore it.
    jerry cowell
    Greenhorn

    Joined: Apr 29, 2010
    Posts: 7
    Thanks for your reply, and sorry for asking silly questions, i don't know a lot of java jsp stuff.
    could you please tell me should i create a blank .java file in the text editor and just copy paste or should i define a class.

    really appreciate your time, can you please give me an example of how i can translate this .jsp file code below to a .java file, what will your .java file look like ?

    *************************
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <%@ page import="sun.misc.BASE64Encoder, javax.crypto.*, javax.crypto.spec.*"%>
    <%@ page import="java.util.StringTokenizer" %>
    <%@ page import="java.util.Map" %>

    <%!
    public String insertSig(String amount, String currency) {
    try {
    if (amount == null) {
    amount = "0.00";
    }
    if (currency == null) {
    currency = "usd";
    }
    String time = String.valueOf(System.currentTimeMillis());
    String merchantID = getMerchantID();
    String data = merchantID + amount + currency + time;
    BASE64Encoder encoder = new BASE64Encoder();
    .......
    ......
    String publicDigest = encoder.encodeBuffer(publicBytes);
    publicDigest = publicDigest.replaceAll("\n", "");
    StringBuffer sb = new StringBuffer();
    sb.append("<input type=\"hidden\" name=\"amount\" value=\"");
    sb.append(amount);
    sb.append("\">\n<input type=\"hidden\" name=\"currency\" value=\"");
    sb.append(currency);
    sb.append("\">\n<input type=\"hidden\" name=\"orderPage_timestamp\" value=\"");
    sb.append(time);
    sb.append("\">\n<input type=\"hidden\" name=\"merchantID\" value=\"");
    sb.append(merchantID);
    sb.append("\">\n<input type=\"hidden\" name=\"orderPage_signaturePublic\" value=\"");
    sb.append(publicDigest);
    sb.append("\">\n<input type=\"hidden\" name=\"orderPage_version\" value=\"4\">\n");
    sb.append("<input type=\"hidden\" name=\"orderPage_serialNumber\" value=\"");
    sb.append(serialNumber);
    sb.append("\">\n");
    return sb.toString();
    } catch (Exception e) {
    e.printStackTrace();
    return "";
    }
    }
    %>
    **************************
    David Newton
    Author
    Rancher

    Joined: Sep 29, 2008
    Posts: 12617

    The code needs to be inside a class.
    jerry cowell
    Greenhorn

    Joined: Apr 29, 2010
    Posts: 7
    Thanks David,
    I am not so familiar with jsp/java, i can understand i have to include it in the class, but my question is will the conversion from .jsp to .java mean a direct copy paste of all objects ?
    how will i translate the html form elements in jsp to java, i mean the ones being appended using the stringbuffer class. i do need them for a transaction.
    can i use html elements in .java ?

    Jan Cumps
    Bartender

    Joined: Dec 20, 2006
    Posts: 2510
        
      10

    "always jerry", you have been asked before to correct your name. Please do so before continuing to post questions.


    OCUP UML fundamental and ITIL foundation
    youtube channel
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61612
        
      67

    jerry cowell wrote:can i use html elements in .java ?

    You have no real HTML elements. All you are doing is creating strings containing HTML markup.

    Perhaps you need to back up a few miles and explain what you are trying to do instead of getting down to nitty-gritty tactics.
    jerry cowell
    Greenhorn

    Joined: Apr 29, 2010
    Posts: 7
    ok here is what i am trying to do.
    I am trying to use a payment gateway to process payments, and the payment vendor has provided a .jsp file(the part of the code above is from that file) that i have to invoke from an ERP program and unfortunately the vendor cannot provide me a .class file and also ERP does not support calls to jsp but has java apis that i can use to invoke a .class file.

    and thats what i am planning to do: convert the .jsp to .java to .class file and go from there.

    ..
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61612
        
      67

    The vendor provided that atrocity? Aye-yi-yi....

    In any case, I assume that the vendor is trying to set things up so you can submit actions to them via the web through HTTP. If you are not doing that, you need to find out what alternate APIs they provide.

    At worst, you can send HTTP requests under Java control using classes provided by the java.net package, or even easier by using 3rd party projects like HttpClient.

    The first step is to find out what APIs the vendor provides, and choose the one that more closely matches your needs.
    jerry cowell
    Greenhorn

    Joined: Apr 29, 2010
    Posts: 7
    we have had some discussions with the vendor and this is the only way out.
    so i have to convert this .jsp to .class and i can use the api's in my erp and i know that will work.

    it would be sweet if you could give me a small sample of how the .java would look like for the .jsp snippet i have provided above.
    i will take it from there. i can very well research over the internet and do it myself, the reason to seek help from experts like you is to get some quick help and in turn i can save some time.

    thanks
    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18887
        
        8

    Well, the Java code for that "snippet" you posted there is precisely the Java code in it. That's everything but the JSP wrapper with the <% and %> bits. You'll need to wrap it in a class declaration of course and provide the appropriate imports (which you can see there).

    Edit: Which I see Bear said 2 or 3 hours ago.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61612
        
      67

    You're still missing the point.

    The purpose of a JSP is to create an HTML file to show on a web page. That's not going to do anything to communicate with the vendor. All "converting" the JSP over to Java will do is to construct a useless string of HTML markup. What will you do with this string?

    What's important is the HTTP API that the vendor expects you to follow. They should have documentation outlining what it is. It could probably (maybe) be garnered second-hand from the JSP (maybe, and certainly painfully), but the JSP itself (and the code within it) is useless except as really really poor "documentation".

    Does this vendor not provide documentation on their API beyond really badly-written JSP fragments?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: how to convert a .jsp to a .java/.class file