How can we write methods in Jsp ?
I want to write methods in jsp in such a way that in one method I should have "Creating database connection" and in another method I want to create ResultSet and in another method I want to access the ResultSet.
u can write methods in jsp using the following tag
<%!
public void myMethod()
%>
Similar Messages
-
How can i write jstl with jsp in sql:update ,when it give sqlException"
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql_rt"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<sql:query var="login" dataSource="jdbc:mysql://localhost/user,com.mysql.jdbc.Driver,user,parul">
SELECT * FROM login;
</sql:query>
<html>
<head>
<title>login information</title>
</head>
<body>
<h1>login information</h1>
<table border="1">
<tr>
<th>id</th>
<th>login</th>
<th colspan="2">password</th>
</tr>
<c:forEach var="round" items="${login.rows}" >
<tr>
<td>${round.id}</td>
<td>${round.login}</td>
<td colspan="2">${round.password}</td>
</tr>
</c:forEach><tr>
<form name="round-input" action="round_process.jsp" method="POST">
<td><input name="id" type="text" size="20" /></td>
<td><input name="login" type="text" size="20" /></td>
<td><input name="password" type="text" size="20" /></td>
<td><input type="submit" value="Update" /></td>
</form>
</tr>
</table>
</body>
</html>
it pass the parameter in round_process.jsp
<!--
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
-->
<sql:query var="login" dataSource="jdbc:mysql://localhost/user,com.mysql.jdbc.Driver,user,parul">
SELECT * FROM login WHERE id=?
<sql:param value="${param.id}"/>
</sql:query>
<sql:update>
INSERT INTO login(id,login,password)VALUES(?,?,?)
<sql:param value="${param.id}"/>
<sql:param value="${param.login}"/>
<sql:param value="${param.password}"/>
</sql:update>
<c:redirect url="round-input.jsp"/>
when i execute the second .jsp page it will show an exception and error that is
javax.servlet.ServletException: Unable to get connection, DataSource invalid: "null"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.round_005fprocess_jsp._jspService(round_005fprocess_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "null"
org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.getConnection(UpdateTagSupport.java:234)
org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.doStartTag(UpdateTagSupport.java:115)
org.apache.jsp.round_005fprocess_jsp._jspx_meth_sql_update_0(round_005fprocess_jsp.java:168)
org.apache.jsp.round_005fprocess_jsp._jspService(round_005fprocess_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.Your problem is that you need to have a
<sql:setDataSource
var="myDataSource"
dataSource="jdbc:mysql://localhost/user,com.mysql.jdbc.Driver,user,parul"
/>and your sql:query would now be
<sql:query var="login" dataSource="${myDataSource}">
SELECT * FROM login;
</sql:query>You can use whatever name you want for the var in the setDataSource as long as it matches the dataSource in the query. -
How can i redirect to my jsp page from servlet in init() method..Becoz that servlet is calling while server startsup..so im writing some piece of code in init() method..after that i want to redirect to some jsp page ...is it possible?
using RequestDispatcher..its not possible..becoz
RequestDispatcher rd = sc.getRequestDispatcher("goto.jsp");
rd.foward(req,res);
Here the request and response are null objects..
So mi question can frame as how can i get request/response in servlet's init method()..Hi guys
did any one get a solution for this issue. calling a jsp in the startup of the servlet, i mean in the startup servlet. I do have a same req like i need to call a JSP which does some data reterival and calculations and i am putting the results in the cache. so in the jsp there in no output of HTML. when i use the URLConnection i am getting a error as below.
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:707)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:705)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:519)
at com.toysrus.fns.alphablox.Startup.callJSP(Unknown Source)
at com.toysrus.fns.alphablox.Startup.init(Unknown Source)
at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
so plz do let me know how to call a jsp in the start up of a servlet.
Thanks
Vidya -
How can i write code in Inbound ABAP proxy method
Hi,
All
Iam doing server proxy ascenario
/people/siva.maranani/blog/2005/04/03/abap-server-proxies
i have done
steps:
1:I have done inbound proxy interface in xi
2:i have created a inbound abap proxy in my SAP WEB AS6.4 using SPROXY.
3:I need to write code in Z11_EMPDETAILS_IN~EXEXUTE_ASYNCHRONOUS method
if i double click on that method it is not opening how can I write code.Hi,
You have to goto the class
<b>ZCL</b>_EMPDETAILS_IN~EXEXUTE_ASYNCHRONOUS not
<b>Z11</b>_EMPDETAILS_IN~EXEXUTE_ASYNCHRONOUS
Check on the third step.
Regards
Vijaya -
How can i write code inside methods.
Hi,
I am new to wbdynpro. How can i write code in Webdynpro?
I have created one layout in that two textboxes are there. After entering the details when i click on the button the datas should be saved into the database table. How can i write code in this.
please help me.
ShyjaHi,
First in context create node for 2 input field. Then disign layout for input filds and do data binding. Then create button and assign ON action event to it. In action method use wizard to read the values from the node.
DATA: Node type REF TO IF_WD_CONTEXT_NODE,
elem_node1 TYPE REF TO if_wd_context_element,
stru_node1 type ZEMP.
Node = wd_Context->get_Child_Node( Name = `S_NODE2` ).
get element via lead selection
elem_node1 = node->get_element( ).
get all declared attributes
elem_node1->get_static_attributes(
IMPORTING
static_attributes = stru_node1 ).
INSERT ZEMP FROM stru_node1.
If helpful reward points.
Regards,
Karthick S -
How can I write the action attribute of a form dynamically using JSP
I would like to do something like this:
If the 'Accept-Language' of the http request is 'en', write out this in JSP:
<form name='myform action="http://127.0.0.1/myservlet/en/>
else if
the 'accept-language' is 'es', write out this instead:
<form name='myform action="http://127.0.0.1/myservlet/es/>
else if no match
<form name='myform action="http://127.0.0.1/myservlet/default/>
How can I do that in JSP? I think this is simple enough so that I don' t need to use any of the Java Web framework/Java Beans.
Thank you for any help.you can use a simple javascript for this:
function setAction(lang){
if(lang=="en"){
document.forms[0].action="putYourservletUrlhere";
}else if(lang=="es"){
document.forms[0].action="putYourservletUrlhere";
}else{
document.forms[0].action="putYourservletUrlhere";
} -
How to access java method in JSP
Hi all,
I need to access java class (abstract portal component) method doContent() in a JSP which is under PORTAL-INF/jsp folder.
I did
<%@ page import = "com.mycompany.Aclass" %>
<%com.mycompany.Aclass a = new com.mycompany.Aclass (); %>
Aclass is coming as autofill/prepopulated with cntrl+space
Till this time, it is working. no errors. But when I do
a.
a. (a dot) no methods are populating (autofill..cntrl+space) or If I forcebly add method a.doContent(req,res)... at runtime its giving error.
It's not only with doContent method... Its with any simple methods in that class or any other class.
(Other than doContent method in the APC java class are prepopulating/autofilling but giving error in runtime)
Can anyone help me... how to access java method in JSP.
I already gone through many SDN forum post... and implemented too---but no use I refered below forum thread
Retrieve values from Java class to JSP
URGENT! How to call a java class from JSP.
Calling a java method from jsp file -
this thread is same as my issue
Thanks,
PradeeP1st. The classes must be in packages. 2nd, the package that they are in must be under the WEB-INF/classes directory. 3rd Look on google and/or this site for web application deployment
-
How to use protected method in jsp code
Could anyone tell me how to use protected method in jsp code ...
I declare a Calendar class , and I want to use the isTimeSet method ,
But if I write the code as follows ..
========================================================
<%
Calendar create_date = Calendar.getInstance();
if (create_date.isTimeSet) System.out.println("true");
%>
============================================================
when I run this jsp , it appears the error wirtten "isTimeSet has protected access in java.util.Calendar"The only way to access a protected variable is to subclass.
MyCalendar extends Calendar
but I doubt you need to do this. If you only want to tell if a Calendar object has a time associated with it, try using
cal.isSet( Calendar.HOUR ); -
List v = new Vector() how can i write this ?
List v = new Vector() how can i write this ?
vector does not 'extends' List rather it 'implements' only ......so how can write this way ? ( polymorphism applies only for 'extends' ).my question in a simple way is :
List some_list extends Vector
No, List is an interface; Vector is a concrete class. Read the javadocs.
Vector implements List
>
AND
List some_list implements Vector
are these two same in behaviour
our apart from theoretical differences ?thanks
Interfaces don't have any implementation; they're pure method signatures. When a concrete class implements an interface, it makes a promise that says "I will provide implementations for exactly these methods. Any client can call a method from the interface and I will do something 'sensible' if I'm written correctly."
From the point of view of static and dynamic types, there's no difference between interfaces and classes.
C++ has interfaces, too - they're classes with all pure virtual methods. If you understand how C++ works, the concept shouldn't be hard.
ArrayList is preferred precisely because it isn't synchronized by default. (You can always make it so using java.util.Collections if you wish later on.) If you don't need synchronization, why pay the performance penalty? -
How can I write bits through the COM1 serial port?
I'm trying to write bits through the serial port COM1.
Labview "Write VI" only writes everything in string. It seems. How can I write bit by bit through COM1?
Thank you,
VanSerial transmission (COM port) protocol requires sending a group of bits at one time. You cannot just send one bit. Standard COM port settings must be either 7 or 8 data bits, 1 or 2 stop bits, etc... You have to group your bits 7 or 8 at a time. You could probably send a 0 byte or a 1 byte. This would be like sending 0000 0000 for a low bit and 0000 0001 for a high bit. Your receiving end would have to know how to interpret what you are sending if you choose this method. Of course you have to convert your byte into a string before sending to COM port. Wire a U8 data type to a Build Array input. Then wire the array output to a Byte Array to String input. The output of this function will be the character representation of your byte suitable for sending acr
oss a serial port.
- tbob
Inventor of the WORM Global -
How can I execute method of Component for name
Hello,
My program has JInternalFrame with some components. Write me please - how can I execute method of Component for name of Component ?
Like this:
... findObject("jTextArea1").cut();
Thank you in advance.just cycle through the container's components until
you find one where getName equals "jTextArea1"Thank you for your answer.
I'm creating components in runtime (I add panel+JTextArea in JTabbedPane) and I don't know how many components will be in JTabbedPane.
I know only it's names.
I wan't to execute metod JTextaRea_n_.cut() via using JTextaRea_n_.Name.
How ? -
How can I write a SQL statement which checks if a table exists?
How can I write a SQL statement which tells me whether a table exists?
execute an sql query: select * from <tablename>
catch the exception n check whether the erroe code
matches the one that occurs for table doesn't exist
that's itHow is your answer any different from the one given in the first reply?
It isn't.
As WorkForFood says DatabaseMetaData has a bunch of methods for getting information about tables but this is more useful when you don't know the names of any of the tables.. it sounds like you do so I would concur SELECT from table is probably the quickest way to go. If it helps the Xopen error should be either S1000 or 42S01 (I think) but I would try and see if there is a specific vendor code for table not found/not exists error and check for that. -
How can i write an image to file
hi everybody,
How can i write a java.awt.Image object to a file.I want to write it to file as a jpg image.Is ther any jpegencoder which can write an Image object to file.
any tips or suggestions
Thanks in advanceThis may be only of limited use but it shows an encoder in use.
http://forum.java.sun.com//thread.jsp?forum=5&thread=140954
http://forum.java.sun.com/thread.jsp?forum=48&thread=446603&tstart=0&trange=15
rykk -
How can i write the data to PIC16F819 using labview?
how can i write the data to PIC16F819 using labview?
Need help!
im using labview in gathering the datas that i need to right to the PIC, then after getting all the datas i am using another program which is ICD2 in order to write it to the PIC. Is it possible to do this task through LV? coz we are spending a lot of time transferring the data from LV to ICD2 manually and its prone to mistake as well.
any suggestion?
thanks,
PedzLabVIEW does not currently have a built-in method to communicate with
i2c, but there are other vendors that sell devices to communicate in
this manner with LabVIEW development kits. One that I know of is
from MCC... here is a link: http://www.mcc-us.com
They sell a device called iPort, and then you can buy LabVIEW VIs to go with it. I hope this is helpful to you!
john m -
How can I write the analogous code to the logic:iterate tag functionality
Hai This is Rayalu .And I am very new to the Java World. I have a doubt?.How can I write the analogous code to the<logic:iterate> tag functionality using the JSP Tag Libraries . Pleae Send me some examples .
Hi,
SELECT objnr objid aufnr
from afih
into table t_afih.
SELECT objnr
from JEST
into table t_JEST
where stat = 'A0045'
OR stat = 'A0046'
AND inact 'X'.
SELECT objnr
from COBRB
into table t_cobrb.
SELECT arbpl werks objid objty
from crhd
INTO table it_crhd
FOR ALL ENTRIES IN it_afih
WHERE objty eq 'D'
AND gewrk = it_afih-objid.
SELECT aufnr objnr auart txjcd pspel gstrp werks aufnr
FROM caufv
INTO table t_caufv
FOR ALL ENTRIES IN it_afih
WHERE aufnr = it_afih-aufnr
And pspel = ' '
AND txjcd = ' '
ANd objnr ne it_crhd-objnr
AND auart in s_wtype
AND werks in s_plant.
AND objnr ne it_jest-objnr.
dont use NE in the select statements, it may effect performance also. Instead use if statements inside
loops.
loop at t_caufv.
read table it_chrd............
if t_caufv-objnr ne it_chrd-objnr.
read table it_jest..........
if if t_caufv-objnr ne it_jest-objnr.
(proceed further).
endif.
endif.
endloop.
hope this helps.
Reward if useful.
Regards,
Anu
Maybe you are looking for
-
Hi Will these following wagetypes populate in RT during the Payroll run? is it necessary to populate. If not populated what happens? /3F1 Ee PF contribution /3F2 Ee VPF contribution /3F3 Er PF contribution /3F4 Er Pension contribution
-
XML publisher report thru fnd_request.submit_request
Hi All, I have oracle application 11.5.10.2 and created many XML publisher reports in RTF format (RDF as a source of XML output) . Now i want to run these reports thru fnd_request.submit_request and generate report output in PDF. I have successfully
-
We have a Live 9i database with archive logging. We now want to setup a standby 9i database, so in case anything happens on Live system we will switch on standby. What are the differences between using a physical standby setup or a logical standby se
-
My websites wont play my flash files
I have 2 websites: gamereviewer and shishamafia. ive made 2 flash banners with adobe flash but when i try to play those files it just get stuck and my flash fails with an error. ,.. i will come back in a hour with a screenshot of the error so its eas
-
I'm sure there is a simple answer to this and has probably been dealt with before but I've done quick search and couldn't find anything... I have a 3008x2000 image that has been processed in photoshop and I now want to place in illy, however when I p