Functions in jsp
hi
I'm newbie to jsp and i want to know is there any familiar thing like a function? i developed some sites before in asp and php ...... and now i'm learning jsp.... what is the best thing in jsp to use if you have the same actions to do a lot of times .... in asp and php you can declare some funtion and call it like
somefunction(adfasdfasdf);
is this beans or servlets?
thanks in advance.
you can create any number of functions and put it in Beans, and now you can create the instance of your bean (scope may be page,session,application) and through that instance call your functions (method), number of methods ,any number of times.
<b> Bean </b>
<code>
class Bean {
String name=null;
public String name(String name) {
return name;
</code>
<b>JSP</b>
<code>
<jsp:useBean id="instance" class="Bean"/>
<%=instance.name("Tom")%>
<%=instance.name("Grey")%>
<%=instance.name("Tomoto")%>
</code>
Similar Messages
-
How to call java script function from JSP ?
how to call java script function from JSP ?
i have function created by java script lets say x and i want to call this function from jsp scriplet tag which is at the same page ..thanks
-
Access session variable in Java Function in JSP
Hi Experts !!
I am developing an application using STRUTS MVC...
Very sorry if u have problem understanding my question, i ll try to improve... and sorry if i can't post codes here
Basic question is ....
I want to open a word document on pageLoad of JSP, the word document is not a single document, there is a form in which there is a "name" and "template" whenever user clicks on a button there is one action attached to it which creates a copy of that template in a different folder.. on the next page OnLoad i want to open that particular document. for that i have created a variable and also have set in the session, just want to access it in the below code.
I have a formbean in which i have a variable, the scope is session, that variable i have put it in session also. but i want to access that variable in a "java function" in JSP so that "onLoad" page that function should work.
JSP---
<script type="text/javascript">
function openDocument() {
var w = new ActiveXObject("Word.Application");
var docText;
var obj;
var a;
if (w != null) {
w.Visible = true;
obj = w.Documents.Open(I HAVE TO ACCESS THAT VARIABLE HERE);
</script>
FORMBEAN----
public class CreateSOWFormBean extends ActionForm {
private String workflowName;
private String comment;
private String sowTemplate;
private String sowFileCreated;
public String getSowFileCreated() {
return sowFileCreated;
public void setSowFileCreated(String sowFileCreated) {
this.sowFileCreated = sowFileCreated;
sowFileCreated is the variable that i have accessed in session and that value i have to pass in that function in JSP....
I am aware of something like
obj = w.Documents.Open(<%'sowFileCreated'%>);
but i m not sure how to write....
Plz help.....If you're working under a framework like struts you should definitely be using JSTL tags rather than scriptlet code to access variables within the page. With JSTL code <% codes can be almost entirely avoided.
To transfer a value from a Servlet to a JSP don't use a session variable, use a request attribute. Session variables should only be used when values have to survive from one transaction to another.
You can write something like:
obj = w.Documents.open('<c:out value="${openURL}"/>');in the Javascript portion of your JSP.
Just beware of potential problems with quotes. The coresponding code in the Servlet would be like:
request.setAttribute("openURL", openUrl); -
How to realize print function in JSP
How to realize print function in JSP? I know use Javascript:window.print() can print,but it will print whole page,it don't fit me;Another method is to write JSP into Excel and then print it in Excel,but it don't fit me too,because it don't print directly. Anybody know how to print it directly?
Many websites offer a "printer friendly" version of a certain page. That IMO is the only way to solve your problem, next to using CSS to use a different style for printer output. Here is a tutorial that covers this:
http://www.alistapart.com/stories/goingtoprint/ -
How to write printing function using JSP?
dear all,
i want to add a printing function in my project but i do not know how to do it? could anyone teach me how to do it?
thanks
ericsalut eric,
you can do it this way :
1 - create a html link in your code to this javascript
function : (I am using Struts, but you can write it in
pure html
<html:link href="#bodyStart"
onclick="openWindowForPrinting()"
titleKey="msg.status.print"> <bean:message
key='app.print' />
<script language="JavaScript">
<!--
window.open = SymRealWinOpen;
//-->
</script>
</html:link>
>
>
2 - here is the javascript function : it open a window
with the "print.jsp" page.
function openWindowForPrinting(){
window.open('/your_project/pages/common/print.jsp','',
'left=150, top=150 , status=no, directories=no,
toolbar=no, menubar=yes, location=no, scrollbars=yes,
resizable=yes, dependant=yes');
3 : here is the print.jsp page : You have only to
create a session variable called
"currentBodyRelativeLocation", which content the
relative URL to the page you want to print (for
example, the boby of the current page).
<%@ taglib uri='/WEB-INF/tlds/perso.tld'
prefix='perso' %>
<html>
<head>
<perso:csslink page='${cssRelativeLocation}' />
</head>
<body onload="var SymTmpWinOpen = window.open; window.open = SymWinOpen; printPage();; window.open = SymTmpWinOpen;">
<body>
<jsp:include page="${currentBodyRelativeLocation}"/>
</body>
<script language="JavaScript">
<!--
window.open = SymRealWinOpen;
//-->
</script>
</html>
<script language='javascript'>
function printPage(){
window.print();
window.close();
</script>
hai,
i'm not very understand how is your code work. when i write html code, do i need to mind about this code: "msg.status.print" ? what is this code mean?
i have too much question on this thing. would you mind to be further explain to me? or is it any reference for me to refer? i'm really new to write printing function on JSP.
i never write this function before. i'm feel so lost.....:(
thanks again
eric -
Passing values to JavaBean function using jsp scriplet
Hi,
I have a JavaBean funtion that is SaveData(parameters)
which save the values from HTML form.
Now i want a code for pass the values from HTML form to SaveData() function using jsp scriptlet.
I used the code
<jsp:useBean id="JDBC" class="bean.JDBCBean" scope="application"></jsp:useBean>
<%=JDBC.saveData(phonenumber,manufacturer,model,email,country,newsletter)%>
Here
JDBCBean -> Bean Name
phonenumber,manufacturer,model,email,country,newsletter ->HTML form's text values
But it didnt work properly.
Anyone help me to correct this.Hi,
i have the same code like above
I have to pass the parameters with form name under the following code.
<jsp:useBean id="JDBC" class="bean.JDBCBean" scope="application"></jsp:useBean>
<%=JDBC.saveData(registration.phonenumber.value,id_type.value,id_style.value,registration.email.value,registration.scountry.value,player_type.values)%>
Here
registration -> HTML form name
But i got the error for
package registration does not exist
out.print(JDBC.saveData(registration.phonenumber.value,id_type.value,id_style.value,registration.email.value,registration.scountry.value,player_type.values));
How to i correct this?
Anyone help me...... -
How to run the recursive function in jsp
hi, can any body tell me how to run
rrays.sort(files);
for (int i = 0, n = files.length; i < n; i++) {
for (int indent = 0; indent < indentLevel; indent++) {
System.out.print(" ");
if (files.toString().endsWith(".jsp"))
System.out.println(files[i].toString());
if (files[i].isDirectory()) {
listPath(files[i]);
indentLevel--;
this code in jsp
thanks in advanceWhy are you writing scriptlets and functions in JSPs?
Functions are supposed to be written in the Java Application layer.
JSPs are best suited only to display information.
Also why are you using Scriptlets insted of JSTL ?
Anyway, if you want to write in JSPs only , here's how to write a function in them: http://forum.java.sun.com/thread.jspa?threadID=496577&messageID=2341986 you can figure out the rest. -
Equivalent function of JSP:include or @include?
Could someone please let me know how I can include html pages in a java servlet page? I am looking for similar function as JSP include. A simple example would be must appreciated. Thanks!
Thanks for you reply. Actually, what I want to do is to import/include a static html page to my java servlet page. I do not want to use JSP because all the pages created were sevlet. I found out a way that using getServletcontext.getResource to read in the html page and print it out from the servlet. Just wondering that if there is a better way to do this?
-
How can I exit a function in JSp
my code is
<%! String Dothis(int level)
if(level==2)
//exit the function
else
%>
How can I exit this function .....
Break label does not work...as I am not able to declare a label
Pl...guide me
smitaLooking into ur code ,,,, U can do it like the following in addition to solutions posted above ( Exception and return)
<%! String Dothis(int level)
if(level != 2)
%>
Thanks
Sampath ... -
Same as PHP Functionality In JSP, HOw?
Hi,
I am a developer having experiance in PHP with Oracle, I recently have projects to develop in JSP, I want know does JSP also have the Variable in Variable functioanlity in as it's available in PHP?
In php I stored my variable name in a PHP variable as
$Asif='My Name is Asif';
$a='Asif';
Echo "Here we can get the result of variable Asif using variable a: ".$$a;
in the above by using $$ it understand the inside value is the actual variable name whose value is to print..
I need same functionality in JSP.....
if Any one can help...
THanks in Advance.
AsifThe same rule applies for textboxes as for checkboxes with the same name - indeed for any components accessed in the dom via javascript.
If there is only one element of that name, it is accessed directly.
If there is more than one element of that name, it reveals them as an array.
so document.testForm.a_date would return an array of input fiels
document.testForm.a_date[0], document.testForm.a_date[1] ... document.testForm.a_date[n]
However the order of submission of parameters is NOT guarunteed, which is why people normally DON'T have fields in this manner - because you can't know for certain that a_date[1] matches with b_date[1] at the server end.
The common practice is to give each field a unique name (numbered). -
HOW CAN I WRITE A EMAIL FUNCTION USING JSP
WHICH HAVE FORWARD, REPLY, REPLAY ALL, AND ADDRESS BOOK LIKE YAHOO EMAIL FUNCTION
HOW CAN I WRITE IT?I meant you would face a considerable challenge trying to write
public static void main(String[] arg) { } with your Caps-Lock key stuck.
You would not even be able to escape your way out of it with
\u0070\u0075\u0062\u006C\u0069\u0063 \u0073\u0074\u0061\u0074\u0069\u0063 \u0076\u006F\u0069\u0064 \u006D\u0061\u0069\u006E(S\u0074\u0072\u0069\u006E\u0067[] \u0061\u0072\u0067) { } as the "\u" escape sequence also contains a lowercase character. -
How to create download function in JSP?
Can I know how to make a download function in JSP? Any sample?. Thank You very much!
http://forum.java.sun.com/thread.jspa?threadID=5312541&tstart=0
Sorry but whining about it in duplicate threads doesn't help.
HELP DENIED! -
How to call PL/SQL function from JSP ?
We have the JSP application developed using the JDeveloper 3.0. I am trying to call the PL/SQL DB function. I'm trying to use the method of ApplicationModule:
.getTransaction().executeCommand(sCommand)
The problem is that I can not get the function result back to JSP. The executeCommand() does not seem to accept any host variables.
What to do ? Did anyone manage to get the feedback from DB ?
Here is the code in the JSP page:
<%! String res=" ";%>
<jsp:useBean id="rsn"
class="oracle.jbo.html.databeans.TRSRowSetNavigator"
scope="request" >
<%
rsn.initialize(application,session, request,response,
out,"theIMO_trs_bc4J_Bc4JModule.AuctionsListView");
rsn.setReleaseApplicationResources(true);
// this is the ID to be copied
String copy_id = request.getParameter(TRS.LOOK_UP_PK_FIELD);
if( copy_id != null) {
// call the PL/SQL procedure to create copy of this auction
String sCommand = "DECLARE a NUMBER; BEGIN :res:=Copy_Auction("
copy_id"); END;";
rsn.getRowSet().getApplicationModule().getTransaction().executeCommand(sCommand);
rsn.getRowSet().getApplicationModule().getTransaction().commit();
I receive the following error:
Error Message: JBO-27121: SQL error during statement execution. Statement: DECLARE a NUMBER; BEGIN :res:=Copy_Auction(45); END;
JBO Error:JBO-27121: SQL error during statement execution. Statement: DECLARE a NUMBER; BEGIN :res:=Copy_Auction(45); END;: ORA-01008: not all variables bound
What criteria has the host variable meet to be used in the executeCommand(sCommand) method ?
Thanks,
Michael
nullI could be wrong there, but I have experienced similar problem on tru64 unix, with sticky bit not in place for the following files: $ORACLE_HOME/bin/oracle and $ORACLE_HOME/bin/oracleO. Once you restore those files via tar command (this is what happened to me), the sticky bit disappears, and you have to re-introduce it by issuing unix command: chmod 1777 on those files.
What it does for you - it allows you to execute the sql statements as an oracle user & group!
Otherwise, if this bit is lost, whenever you try to connect to sqlplus via user / password it hits you back with:
ORA-01034 ORACLE not available
ORA-27121 unable to determine size of shared memory segment
Compaq Tru64 UNIX Error: 13:Permission denied
This should not be a problem if you try and execute the same sql statements using listener (connecting to the server by using @ statement).
I could be late in response to you, but maybe not for other people. -
How to implement this function in JSP/Servlet env?
Hi all,
I working on a project, it provides functionality to upload file using JSP/Servlet. In the first JSP page, there is file location and submit button. After user select a file to upload and click submit button, a message, like "sending file to XXXX", will be shown on the screen. Once uploading and validation are done on the server-side, a successful/error msg will be shown to user.
Here I have a question for the "sending..." msg and the successful/error msg. They should be put in one jsp page or in two separate page? how to implement them?
Thanks for any help!
TranquilFor the sending message... Well, the thing is, when you click submit, it's sending the file to the server and the server is processing it, and this is all done before the "complete" page is sent to the server. So one would need to use some Javascript on the page before the actual submit happens to show some message. This is done on Ebay when you put something for sale, you can upload an image, and there is a little popup message telling you that it's uploading, and it is removed when the process is done. Now, I'm not sure the exact details of how this works, but my educated guess is this:
1) The onsubmit function of the form checks that the file upload fields have a value (no need to popup a message if no file upload, since that's what usually takes the time, although it could just be assumed there is a file). If a file is to be uploaded, or just want to show the message anyway, a new popup window is opened with the window.open method and the "sending" message is shown (either written via Javascript or just load a small web page to the window).
2) The popup window, since you can't transfer the window object from the form page to the next page, has to check window.opener for some value that the success/error page would have to set. The success/error page could use it's body onload function to set a variable in it's own window object to denote that the page is loaded. The popup window can use a looping check using setTimeout or setInterval in Javascript to check for window.opener.isLoadedVariable to be present, and if so, close itself.
I've never done that, but I see no reason why it wouldn't work. -
Hi to all,
I would to use simple functions in my jsp page.
I 've created the function with the tags <%! ... %>
My problem is that i don't succed to call there from the page.
How i can to do ?
I've tried also with java beans but i'm not very clever with there also so i don't can to go forward !!!
Please help me. thanksHi, a new problem rises now.
the problem is into the method ctr_data().
Under i put the jsp code and the error:
Anyone can see where is the error please?
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import= "java.sql.*, java.lang.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Progetto Sofia - Registrazione utente</title>
</head>
<%!
public boolean ctr_lunghezza(String s1){
if (s1.length() == 0) return false;
return true;
%>
<%!
public boolean isLeapYear(int year) {
if (year%400 == 0) return true;
if ((year%4 == 0) && (year%100 != 0))return true;
return false;
%>
<%!
public boolean ctr_data (String gg, String mm, String aa){
int anno = Integer.valueOf(aa).intValue();
int mese = Integer.valueOf(mm).intValue();
int giorno = Integer.valueOf(gg).intValue();
if ((gg.length() == 0) || (mm.length() == 0) || (aa.length() == 0))
return false;
if ((anno < 1905) || (anno > 2005))
return false;
if (mese == 2){
if (isLeapYear(anno)){
if (giorno > 29) return false;
}else{
if (giorno > 28) return false;
if ((mese == 11) || (mese == 4) || (mese == 6) || (mese == 9)){
if (giorno == 31) return false;
return true;
%>
<%
int flag = 0;
String risposta = "";
String temp ="";
temp = (request.getParameter("nome_utente")!=null)?request.getParameter("nome_utente") :"";
if (ctr_lunghezza (temp) == false){
risposta = risposta.concat("Attenzione --- Riempire il campo: Nome\n");
flag++;
temp = (request.getParameter("cognome_utente")!=null)?request.getParameter("cognome_utente"):"";
if (!ctr_lunghezza (temp)){
risposta = risposta.concat("Attenzione --- Riempire il campo: Cognome\n");
flag++;
String gg1 = (request.getParameter("giorno_n_utente")!=null)?request.getParameter("giorno_n_utente"):"0";
String mm1 = (request.getParameter("mese_n_utente")!=null)?request.getParameter("mese_n_utente"):"0";
String aa1 = (request.getParameter("anno_n_utente")!=null)?request.getParameter("anno_n_utente"):"0";
if (!ctr_data(gg1, mm1, aa1)){
risposta = risposta.concat("Attenzione --- Data di nascita non corretta\n");
flag++;
temp = (request.getParameter("luogo_n_utente")!=null)?request.getParameter("luogo_n_utente"):"";
if (!ctr_lunghezza (temp)){
risposta = risposta.concat("Attenzione --- Riempire il campo: Luogo di nascita\n");
flag++;
temp = (request.getParameter("res_utente")!=null)?request.getParameter("res_utente"):" ";
if (temp == "Seleziona"){
risposta = risposta.concat("Attenzione --- Selezionare il Comune di Residenza\n");
flag++;
temp = (request.getParameter("ind_utente")!=null)?request.getParameter("ind_utente"):" ";
if (!ctr_lunghezza(temp)){
risposta = risposta.concat("Attenzione --- Riempire il campo Indirizzo\n");
flag++;
%>and this is the error msg:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: For input string: ""
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NumberFormatException: For input string: ""
java.lang.NumberFormatException.forInputString(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.valueOf(Unknown Source)
org.apache.jsp.progetto.w2.web.Reg_005futente_jsp.ctr_data(org.apache.jsp.progetto.w2.web.Reg_005futente_jsp:27)
org.apache.jsp.progetto.w2.web.Reg_005futente_jsp._jspService(org.apache.jsp.progetto.w2.web.Reg_005futente_jsp:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) -
Hi all
can someone please tell what am I doing wrong here? I'm trying to call Function on a JSP page
CallableStatement cs = connection.prepareCall("{? = call pa_dump_xml.fn_user_diary(?)}");
ResultSet rs = cs.executeQuery();
while (rs.next()) {
%>
<input type="text" name="app1" id="textfields1" size="" value="<% out.println(rs.getInt(11));%>" readonly="readonly"/>
<%
rs.close();
%>... And I keep getting this error
root cause
javax.servlet.ServletException: java.sql.SQLException: Missing IN or OUT parameter at index:: 1ThanksThanks for your reply, this is my code ;
CallableStatement cs = connection.prepareCall("{? = call pa_dump_xml.fn_user_diary(?)}");
proc.registerOutParameter(1, Types.INTEGER);
ResultSet rs = cs.executeQuery();
while (rs.next()) {
%>
<input type="text" name="app1" id="textfields1" size="" value="<% out.println(rs.getInt(1));%>" readonly="readonly"/>
......And the error I'm getting is
java.lang.NullPointerException It's a JSP page as an index page where I need to show Data in some textfields on load of page. I'm sure there is a better way of doing this but I can not think how to go about it.
Thanks
Zed
Maybe you are looking for
-
All-Day-Events Not affecting Availability
Hi All, We have iCal server setup on 10.5.4 and I've come across a bug in the iCal client (3.05). If someone has created an event and checked it as All-Day, that event will not affect that users availability if someone else tries to add them as an at
-
How to open a BUP file from a flashdrive in Macbookair?
Pl let me know how to view a video with BUP extension from a flashdrive in my macbookair?
-
Hi All ! In my smartform, I am using 2 logos for 2 different compnay codes. For only 1 company code the logo is not getting displayed, But for the other company code it is working perfectly fine. Please advice.
-
I need to download itunes on my iphone but I do not have a homecomputer is there another way I can download itunes?
-
I have two Zens that is the type of player, plain Zens, no letters attached.
I have two Zens that is the type of?player, no letters after Zen. I want to sync them both on my PC, not at the same time. I don't want to overwrite what is in each player. You advice appreciated.