Getting the actual jsp line number from a stack trace line number? - java

Here is the stacktrace:
...
org.apache.jsp.showcustomer_jsp._jspService(showcustomer_jsp.java:128)
org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
This is what I do:
Get the line number from the stacktrace, in this case 128.
Find the showcustomer_jsp.java file (and it isn't exactly obvious to look in /var/run/tomcat-6/Catalina/localhost/_/org/apache/jsp).
Open it and go to line 128.
Now, search the .jsp file for the whatever you found on line 128 in the _jsp.java file.
Boom! You're done!
Please, is there a simpler way to do this?

I have found this page on Eclipse WTP FAQ which explain how to configure Eclipse so that you can go to the generated java code clicking on the stacktrace.

I don't think you can. The JSP file is compiled into a servlet, and is not run directly. As the exception is thrown from this servlet, the line you have in the stack trace is the one from the class. The original line in the JSP is lost at this point.
Usually it is best to avoid writing code or throwing exceptions from a jsp, and encapsulate your logic in servlets and JSP tags, and use JSTL for control flow (if, forEach, etc.)

I used to program in Lex and Yacc which would generate C code, and you could enable #line pre-processor directives for debugging. When something happened in generated c code, then the IDE was smart enough to open the corresponding lex or yacc file, and not the generated c code. Surly

Related

Running java codes one by one on server-side JSP

Let's explain my graduation project then my question.
My graduation project is about compiling java code online.
To compile user's code, I am using java compiler api on background bean class. After compilation is finished .class file is generated on the D:\eclipse-jee-mars-R-win32-x86_64\eclipse directory. Then the progam saves input file that is writed in text area(in JSP) to D:\eclipse-jee-mars-R-win32-x86_64\eclipse directory. After creating input file, the program runs the code by using dos command at runtime and process getInput stream. The getInput stream returns output of the code. If entered code(user's code) creates any output file, output file will be generated also.
We suggest for users that "your code's output file name should be 'output.txt'".
If the user's code creates any output file. "output.txt" file is generated on D:\eclipse-jee-mars-R-win32-x86_64\eclipse directory.Then, the program retrieves 'output.txt' contents to JSP and show the "output" of their codes to users.
Thus far, there is no problem. Problem is starting here. For one user there is no problem but think for 2 users or more. If 2 or more users compile codes at the same time problems will occur because their .class .java and "output.txt" files will be the same file because for all users we creates same name file on D:\eclipse-jee-mars-R-win32-x86_64\eclipse directory. Maybe for all users, creating files as unique name will help me but it creates another problem. Our project also analyse codes by looking runtime of the codes. This solution[unique name] brings parallel working codes and analysis results will be unfair. Because sometimes 1 code is worked, sometimes 100 code is worked on the website.
I need to compile, execute, analyse codes one by one, not parallel.
How can I solve this problem? What a solution can be used for this situation?
"Accepting random code from the internet to compile/run it server-side" - this sounds like a particularly bad idea, opening you up for all kinds of nasty attacks. DOS (Denial of Service) being only one of them.
Further, the architecture to externally execute code and share a common well-known file - as you state - makes it impossible to execute more than one of these programs at the same time
Storing this external code in some IDE's directory is another weird thing to me.
In fact, I think that this whole architecture is such a bad idea that I have a hard time suggesting a solution other than to rethink it: If you have a very good reason for accepting random code from the internet (other than researching exactly this question), please state it here.
With protest (and the suggestion to not follow this tip) I'd point to the option to just pipe the application's console output (e.g. System.out) back to the client instead of that one single wellknown file. At least now you can safely be attacked by many users coming in parallel, without mixing up the replies.
I solved my problem with using synchronized block. It is enough for my project.
In project JSP file.
synchronized(this){
//my compilation, running and analysis part is here
}
Now, one thread can process this part. It means that, for thousands users all codes are processed one by one. No parallel working codes.

How can i figure out instruction pointer address in the certain part of my java code?

I'm just trying to get a memory trace generated by Java code(JVM) using pin tool(pinatrace). But every result of the microbenchmarks I try to figure out the traces shows almost same graphs, and even utilizing processbuilder inside Java code gives no remarkable results at least in comparing among different microbenchmarks. I realized that I should extract the substantive part(excluding useless part for analysis, like initializing, accessing to JVM in the middle of main code....) of the code to figure out what is going wrong.
Because the instruction pointer is sent to pinatrace at the moment it detects memory access, I thought getting the instruction pointer of substantive part and set the parameter with those information would work. But Finding the way(or the tool) for this job is driving me crazy, since Java is not a familiar field to me....
I've already tried IDA pro, but it only says The input file format is wrong, when I input .class file. and setting .java file as input shows me just binary code which seems like the text file is converted to binary things and nothing. Tried to install IDAjava addon but also does not work....... Is there any easy method to get the IP instead? what I just want to know is IP from java code..
Thank you!

when is debugging work for java

I am new to java.I have a doubt that only ".java" files supports debugging whereas the
".class" files does not supports debugging in IDE.
Can you please suggest an answer?
Most IDE's (I know eclipse does, and pretty sure IntelliJ and netbeans do) will allow you to step through the processing of a class file, however they won't let you see what code is being executed, however you can see the variables in use. However to get there you will need to add a breakpoint in your code, and step down to the relevant class file. If you can attach the source, it will let you see the code being executed, as well as add a breakpoint directly in the file in question.

How can I add to the "Error Log" section in Eclipse?

I am trying to make an Eclipse plugin that enables a student with no knowledge of English to code. So I want to take the errors of what he coded [in his own language], translate them and put them in the Error Log for him to see and understand.
How can I write in the "Error Log"?
I'm unclear of the use case here. But based on partial understanding, here is what you can do. You can wrap each exception/error with your exception hierarchy with language/locale of your choice and then print out wrapped error/exception into it. Keep this log file in the project path, so it will be accessible from within. Parse it and display it as and when it gets updated. So instead of checking the error log panel, you can see your log file for the reference.

I want to read the xml response displayed in the eclipse console to assert with the expected xml.

I want to read the xml responce displayed in the eclipse console to assert with the expected xml. Can somebody please help me to read the output from the console of eclipse while running my test....
I am not sure if you are trying to assert two XML's using Junit etc? Also I am not sure of what you mean by reading from Console?
If you are writing the code to assert using two XML's using Junit & XMLUnit Below link can help.
XML's Comparison
XML unit's Example Code
The Eclipse console simply displays what's printed to the standard output. If you aren't concerned about spurious output, then you can quite simply print whatever information might be useful to standard output, and it should end up there, assuming that you have the debugger properly attached to the running process.
I can't think of a ready way to do it automatically when an assertion fails, though, since it will most likely be local in scope (so you can't catch and rethrow the generated exception).
Simple calls to System.out.println() should give you a start.

Categories

Resources