How to not execute jsp code inside jsp - java

I have a requirement where i have to create widgets and display the source code on the web page to the user. The source code is jsp. But how can i stop executing jsp inside jsp page.
Is there any way?
Thanks.

Related

Can you change the text content of a JSP file by code (on the fly)

Lets say I have a jsp page in my webapp. The code inside it displays some info.
Can I change the code (text) inside this jsp using a Rest Controller. I want to dynamically replace its code by opening the file and changing its content.
I want to change file content via http request:
"/api/change-jsp?newcontent=sometext&file=example.jsp"
--> The corresponding rest controller now does his job.
Will that work or not ?
Ps: 'newcontent=sometext' contains jsp code (EL)
It won't work — jsps are compiled at runtime by the servlet container when the app starts. The JSP compiler will not expect the jsp to change.
But why change it in the first place? Just make the jsp ask for the information it needs.

Java EE Clarification on Workflow for JSP and Servlets

I am attempting to learn Java EE. After struggling through trying to understand the Java stack, it appears that that a basic dynamic web application can be accomplished by focusing on JSP and Servlets so I want to start there.
In Net Beans I have a basic project set up with a tomcat server and when I hit run I can get the web page to generate and display the default index.jsp page. I have added a css file to the project and this jsp page looks like any standard html page now. I then create a new servlet. I was also able to create a link in the index.jsp page so when I click on it, it calls the servlet.
What I don't understand is why when I create the servlet in Net Beans, the processRequest method comes pre-populated with several html print statements. I could easily make this page look like the jsp page I started with, making me wonder why I even need a JSP page. It appears the entire application could be comprised of servlets.
Could someone please explain the proper interaction between the two? It appears the index page can contain links that call various servlets, perhaps to access a database of comments, then do I create the response table in the servlet, or would I pass that information to another JSP page?
Understanding these basic workflows would really help. Thanks
JSP also a kind of a servlet . Right after you run the jsp , go to your netbeans project directory and right click the jsp and select view Servlet then you get the servlet representation of your jsp file. Actually jsp file is there to perform front end design easily. Without jsp It is really difficult task to perform front-end developing stuff inside servlet.
And you should keep in mind there is no such a thing called proccessRequest in javaEE . It is automatically generated by Netbeans once you create a new servlet. So just stick to basics. Erase all the auto-generated stuff from the class which has extended HttpServlet. And then you can override the required HTTP method/methods. (doGet , doPost etc..) You should take a look at this for more infromation ...
And this page will also improve your knowledge on javaEE

Call an applet through a JSP site

I have create a simple Hello World Applet and I have save the .class file to the server where the JSP site is.
I want help so what I have to write in the JSP Site so whenever through the Browser I open this specific JSP Site this applet also run and show the message Hello world.
The JSP site and the .class file from the applet are at the same root, for example *D:\server\tomcat\test*
and also if someone can explain me what is the appletviewer and if I need something like this in my case?
You add an applet to an html page.
The jsp page gets compiled and when it runs its spits out html.
So in your browser all you will have is html.
So you basically need to embedd you applet to the html that is generated by your jsp page.
I would suggest you to do some research on adding your applet to html.
Once you have that, simply append the resulting html code (which has the applet) to your jsp page.
Embed the applet in the file by adding the following applet tag anywhere between the file's tags:
In an HTML file: <applet code="org.me.hello.MyApplet" archive="HelloApplet.jar"></applet>
In a JSP file: <applet code="org.me.hello.MyApplet" archive="HelloApplet.jar" width="600" height="480"/>
The jsp will ultimately spit out the html code.

IE/Firebug Debugger. Is there a way i can find out JSP file name?

How to see the which JSP file contains the given UI element like textbox in IE/Firebug Debugger?
Is there a way I can find out JSP file name? Even in firebug I don't see the jsp file name? In Internet Explorer debugger, when I do find select by element, it takes me to exact element source code. But it does not show
up JSP file name which contains this text box.
Say I am on any web page on internet explorer which contains some text box. I want to know the jsp file name which contains this text box.
JSPs are executed at server-side, and generate HTML. The browser doesn't know and doesn't care about the JSP. It goes to a URL, and takes the HTML from the response.
If you want to know which JSP generated some part of an HTML page, then discover to which servlet or JSP is the URL of the page mapped (provided this part is not generated by AJAX), and follow the path of the request from this servlet or JSP until you find the one that generates the given HTML part.
It can help to include a HTML comment at the start of every JSP, to be able to track that more easily:
<!-- Start of JSP foobar.jsp -->
This way, by looking at the HTML code, you just have to go up until you find such a comment to know which JSP generated it. But every JSP has to follow this rule.
Right click on page and select "ViewPageSource" from the menu.You can find the corresponding jsp.

Dynamically load source in div on jsp page

I am using struts 1.3 framework.
I have come across a scenario that, I have set of Struts Action URLs on JSP page.
I want to load source for all of these URLs dynamically without refreshing jsp page, and each into a separate DIV.
Any pointer will be of great use.
JQuery and AJAX is your answer!
http://jquery.com/
(JQuery has AJAX built in FWIW)

Categories

Resources