How to include servlet in JSP using Include Directive?
Hi experts,
am a beginner to JSP.. I want to know,
is it possible to include a servlet in jsp using include directive? could any one explain me...
No it is not possible.
Include directive is like copying and pasting some text into a JSP file, and then translating/compiling it.
So the only thing you can include with the <%@ include %> directive is a jsp fragment
It is a static translation/compile time include and thus will always be the same
By contrast <jsp:include> is a runtime include, and includes the result of running the imported url.
That URL has to be a complete/standalone jsp/servlet/whatever. However as it is runtime, it can take parameters where the include directive can not.
Does that answer your homework question?
Cheers,
evnafets
Similar Messages
-
How to combine servlet and jsp
I'm doing a project. My friend using jsp. and i using servlet..
we are confused, how to combine servlet and jsp. or we can just use redirect??
but it's still doesn't work properly...thanks for your helppYou can use RequestDispatcher interface for calling a JSP from a Servlet, or vice-versa.
Following is the code for sending output to a JSP page from a servlet:
javax.servlet.RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(�/Ashu.jsp�);
request.setAttribute(�Name�,�Ashutosh�);
dispatcher.forward(request,response);
- Ashutosh -
How to do validation in jsp using javascript
how to do validation in jsp using javascript
The same way you do with any HTML page.
Catch the onclick/onsubmit event, do your validation in javascript and then allow/cancel the action as required.
However this is javascript validation only - javascript can never call JSP code. -
Pass data from servlet to jsp using sendRedirect
Hi,
I am passing data from servlet to jsp using forward method of request dispatcher but as it doesn't change the url it is creating problems. When ever user refreshes the screen(browser refresh) it's re-loading both servlet and jsp, which i don't want to happen. I want only the jsp to be reloaded.
Can I pass data from servlet to jsp using sendRedirect in this case. I also want to pass some values from servlet to jsp but without using query string. I want to set some attributes and send to jsp just like we do for forward method of request dispatcher.
Is there any way i can send data using attributes(without using query string) using sendRedirect? Please let me knowsendRedirect is meant as a true redirect. meaning
you can use it to redirect to urls not in your
context....with forward you couldn't pass information
to jsps/servlets outside your own context.Actually, you can:
getServletContext().getContext("/other").getRequestDispatcher("/path/to/servlet").forward(request, response)I think the issue here is that the OP would like to have RequestDispatcher.forward() also update the address in the client's browser. That's not possible, AFAIK. By the time the request is forwarded, the browser has already determined the URL of the servlet, and the only I know of way to have the browser change the URL to the forwarded Servlet/JSP is to send a Location: header (i.e. sendRedirect()). Remember that server-side dispatching is transparent to the client. Maybe there's some tricky stuff you can do with JavaScript to change the address in the address bar without reloading the page?
Brian -
How to call Servlet from jsp page and how to run this app using tomcat..?
Hi ,
I wanted to call servlet from jsp action i.e. on submit button of JSP call LoginServlet.Java file.
Please tell me how to do this into jsp page..?
Also i wanted to execute this application using tomcat.
Please tell me how to do this...? what setting are required for this...? what will be url ..??
Thanks.well....my problem is as follows:
whenever i type...... http://localhost:8080/appName/
i am getting 404 error.....it is not calling to login.jsp (default jsp)
but when i type......http://localhost:8080/appName/login.do........it executes servlet properly.
Basically this 'login.do' is form action (form action='/login.do').....and i wanted to execute this from login jsp only.(from submit button)
In short can anyone please tell me how to diaplay jsp page using tomcat 5.5
plz help me. -
How to display PDF in JSP using Iframe
Hi All,
I am using Struts 2. I am building my file in ActionClass with seperate Method like getGeneratedPDF() in which, I am setting header of response and writing into PDF.
This method will be called from JSP by this way
s:property value="getGeneratedPDF()" />
But It displayed Junk Characters , and this PDF is not static (already Generated). It is generated and build on Fly.
I have 2 questions 1 -- How to display PDF in JSP in proper way without Junk Character in it?
questions 2 -- How to display it in Iframe?
Please help me , If you know the solution.
Thanks in Advance,
Jimmyjamy_26 wrote:
But It displayed Junk Characters , and this PDF is not static (already Generated). It is generated and build on Fly.A PDF file is a binary file, not a text file, and you're trying to display it as String. Of course you would get "junk characters". Have you ever tried opening a binary file (pdf, doc, jpg, xls, etc) using a text editor like Notepad?
I have 2 questions 1 -- How to display PDF in JSP in proper way without Junk Character in it?Display it as binary stream, not as text stream. You can display it standalone, just let the link/form/addressbar URL point to some Servlet which writes the InputStream of the PDF file to the OutputStream of the response, along with a correct set of response headers (at least content-type, content-disposition and content-length), so that the browser can open it in the correct application (which is usually Acrobat Reader). If you want to embed the PDF file in a JSP, then one of the ways is indeed using the HTML <iframe> tag.
questions 2 -- How to display it in Iframe? Just let the iframe URL point to the aforementioned Servlet.
You can find here an example of a generic file servlet, you may find it useful to get the idea how to do it: [http://balusc.blogspot.com/2007/07/fileservlet.html]. -
i m trying to call it from jsp using
<a href="../purchaseP?orderno=<%=pno%>"><%=pno%></a>
but its giving error..
type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).i m trying to call it from jsp using
<a href="../purchaseP?orderno=<%=pno%>"><%=pno%></a>
but its giving error..
type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed
for the requested resource (HTTP method GET is not
supported by this URL).Are you implementing the doGet or doPost method in your servlet? If you are calling from a hyperlink then it needs to be implementing the GET method. To access the POST method use a html form. -
Urgent: how to call servlet from JSP
I have a working servlet which returns a table in html format. I also updated the web.xml file according to the information I got from the previous message. My problem is how to correctly invoke the servlet in the JSF. I tried the following ways:
<jsp:include page="/report">
<jsparams>
<jsparam name="srcDev" value="#{Page1.srcDevice}"/>
<jsparam name="tgtDev" value="#{Page1.tarDevice}"/>
<jsparam name="format" value="complete"/>
</jsparams>
</jsp:include>
and
<frame src="/report?param1=val1¶m2=val2" name="body" frameborder="YES" scrolling="YES" bordercolor="#999999" noresize>
both doesn't work.I am able to run the servlet within a html form. I just don't know what's the right syntax for calling the servlet inside a JSP page in JSF.
Can anybody help me?
Thanks,
ChristineHi Christine,
This forum is exclusively for Sun Java Studio Creator related issues.
In case you are using Creator then you can find a sample application named RedirectionExample which makes use of a servlet and would be of help to you. You can find the tutorial on the following page:
http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
Cheers
Giri :-) -
How to install servlet and jsp on win xp?
I am new in jsp and servlets. I would like to follow some jsp books and examples. The j2eesdk-1_4-dr-windows-eval.exe is already installed on my computer. I can write and run java codes. I downloaded the jsp-2_1-edr-api.zip file from http://java.sun.com. I extracted and moved to dir:\Sun\AppServer\ folder. When I search, I cannot see any jsp.jar file as some documents say, nor servlet.jar. How can I install jsp and servlet on windows xp? Any help? I will be very grateful.
For starters, you would probably have better luck getting an answer on the general Java forums, since this a very general question- it is hard to see how this is specific to the Web Application Framework technology, except of course that it uses JSP and servlets naturally,
But to try to help you here, more information is needed: from exactly where are you do\wnloading the file jsp-2_1-edr-api.zip and what is the product title of this file? I ask this since a general search of sun.com returns no evidence of the existence of this file.
Also, what documents are being referred to here?
Thanks -
How to call servlet from jsp in portal applicaton...??
JDeveloper - 11.1.1.6.0
Hii all, i am working on an portal application in which i have added my adf application as portlet..
in this adf application i am having an jsp page on the popup
the action of this jsp page is set to an servlet
<form id="form1" action="servlet/UpdateServlet">
<input type="text" name="test"/>
<input type="submit" value="SUBMIT"/>
</form>
But when i click on submit button, the servlet is not being called..
The servlet is -
public class UpdateServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
public void init(ServletConfig config) throws ServletException {
super.init(config);
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String value1 = request.getParameter("test");
System.out.println("one : "+value1);
Any help on this
Thanks
Edited by: 938480 on Oct 3, 2012 1:56 AMWhich application server you are using.
I am using JRUN SERVER.
For me it is very easy
I have to put my servlet in web-inf/classes/xx.class.
Then i can run like
http://localhost/xx.
Let me know which server u are using. -
How to pass paramter JHeadstart jsp using setCurrentRowWithKeyValue
How i can use setCurrentRowWithKeyValue or other ADF function to pass one value to JSP / JHS page and Jheadstart give me rows matching this parameter value passed to this page
JHS use setCurrentRowWithKey but now i need to pass a value not a rowkey
for example an deptno to emp.jsp page
<a href="Emp.do?event=setCurrentRowWithKeyValue&deptno=10/>FetchValues</a>
this is possible ? there is an easy way to do this ?
tnxHi sandra tnx for response my question is how to be in capacity of access any JSP page on my JHS Proyect directly using programmatic links depending of some situations.
There are some master pages that have details pages for example on simple oe schema
Customer -> Orders Page -> Order Items
How from Customer Page i can directly call and Order Items Page and pass parameters?
if i use native JHS navigation functionality when i click details on Customer page JHS pass parameter and save some info on session depending of row key selected and show Orders Page
There is a way Having a link on Customer page call a programmatic event onSaveSomeParam save param of Order Number and then call Orders Items page ?
I also try using native search functionality of JHS
a href="orditem.do?queryOperatorNonString=is&queryOperatorString=startsWith&event=quickSearch&eventValue=true&searchAttribute=Id&searchText=<c:out value="${orditems.Id}"/>">Order Items
off course it send me an missing IN OUT parameter because JHS is waiting for
Orders Page param to be set
If u have some sample code i really appreciate
tnx....
Mensaje editado por:
mr2k -
How to resize image in JSP using JAI ??!!
Please help me how to resize an JPEG image from my JSP, could I use JAI lib ? how ?
Hello,
I had the same problem few months ago ( in that case i used Jimi instead of JAI).
The answer to your question is: use the java class called "Image".
Infact you can use JAI just for load or save to disk your image that you have to resize and then use the following code to resize the image :
Image imgResized = img.getScaledInstance(100,1,Image.SCALE_AREA_AVERAGING);
The object "img" is the image to resize and the object "imgResized" is the image resized with width equals to 100 and with a right height.
I used Jimi just to save my image and i think that with JAI there is a method to do this.
You can use JAI to load in memory your image too so you can avoid problem with MediaTraker class.
I hope that this can help you.
Cheers.
Stefano -
How to run servlet and jsp in Eclipse
i am trying to run a jsp and servlet file in Eclipse its showing error in editor its self.
yep, eclipse can do that. I've never done it, but
Tomcat needs to have remote debugging enabled, which
means you need to use the tomcat that WASN'T
installed by an installer. don't ask me why, ask the
boys at Jakarta! eclipse attaches itself to the
debugger in some way or other. I dunno. there's a
book called Eclipse Distilled that only costs about
?10 or so and has a chapter on doing exactly this, if
you're using Eclipse for fairly advanced stuff like
this, I'd invest in a copy of that. well worth the
moneyTry [url http://www.eclipse.org/webtools/]WTP★ plugin (Web Tools Platform). I am using this plugin, and as far as I know it is free. You just have to install Tomcat normally, and configure WTP plugin to pointing that Tomcat. You can run, debug, do everything you want. -
How to set JavaBean in JSP using JavaScript function
Hello,
When a user clicks on an item, I want to execute a JavaScript function. Within that function, I want to set specific JavaBeans (<jsp:setProperty... />) within my JSP page.
Can anyone tell me how to do this or where I can find examples on how to set JavaBeans in a JSP page using JavaScript?
Thanks.
Pattry this:
your.jsp
<html>
<SCRIPT>function buttonClick()
{document.compform.submit();}
</SCRIPT>
<body>
<form name=compform method=post action='your.jsp'>
<%
//write your code which you want to execute once the button is submitted
String submit;
submit=request.getParameter("mysubmit");
if ((submit != null) && (! submit.equals("")))
%>
<input type=hidden name=mysubmit value="submit">
<input type=button value=add onclick='buttonClick()'>
</form></body></html> -
How to run servlet from JSP page
A simple JSP page,where I will put a button.And on clicking..it will invoke the servlet and the servlet will send the result to the jsp page...
Please give the instructions with examples...
Thanks in advance...hi,
Create a jsp inside webapps/root
<a href="./howtocode" > click to call servlet </a>and follow the steps
http://forum.java.sun.com/thread.jspa?threadID=5202830
Maybe you are looking for
-
I just bought a MacBook Air and don't want to store all my photos on it. I'd like to be able to store and access them on a separate back up disk but iPhoto won't allow me to access these saying: "The iPhoto library is a Time Machine backup, and so ca
-
My iPhone will not update. The update has downloaded but when it says verifying with Apple it comes up with an error 3014. When I checked that error out, it says I need to make space on my hard drive but I have 52% space left. Any suggestions?
-
After upgrading on both a Mac Pro and MacBook Pro I encountered several problems with Mail. On MacBook Pro: Unable to receive email for certain accounts Was able to delete the offending accounts and add them and this solved the problem. On Mac Pro: U
-
I haven't received a single email to my iCloud (@me.com) account since Friday - I know there must be some sort of problem because I have ordered from Amazon and Tesco, who always send confirmation emails but I have received nothing. I've already chec
-
Hi, I have te same post earlier; the website was down while posting; so, I reported. Please ignore this. Hello: I would like to know if time dimension works if there are 14 periods ( 12 months + two more values that refer something else)? Can we crea