Bean Introspection in jsp
can Bean Intrspection help me to save the uploaded file ?
I am using a html form which contains few employee information with a upload field for employee's picture. now i want to know, is it possible to save the uploaded image(jpg) into java bean like other properties ?
I am using a html form which contains few employee
information with a upload field for employee's
picture. now i want to know, is it possible to save
the uploaded image(jpg) into java bean like other properties ?Basically, if I read your problem correctly...you have a form which contains few normal text/form fields + a file to be uploaded? This is a problem concerning Multipart Http Request. Yes you can do it in JSP/Servlet. b.t.w., Struts handles it very well. Google for "Multipart Request FileUpload Servlet"
-BJ
Similar Messages
-
Database access by Bean, error in JSP(view)
Hello,
I have a web application. All my database connection logic, execution of query is done in my bean. I have verified that the code in my bean is fine and so I have not posted that code.
My jsp code is as follows:
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<html>
<head><title>Trial JSP Page</title>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-STORE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="PRIVATE">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</head>
<jsp:useBean id="data" class="com.bean.samples.ConnectionBean"/>
<jsp:setProperty name="data" property="drivername" value="oracle.jdbc.driver.OracleDriver"/>
<jsp:setProperty name="data" property="url" value="jdbc:oracle:thin:@someurl"/>
<jsp:setProperty name="data" property="username" value="name"/>
<jsp:setProperty name="data" property="password" value="passwd"/>
<jsp:setProperty name="data" property="query" value="SELECT * FROM tablename"/>
<%
data.processQuery();
ResultSet rs = data.getRs();
ResultSetMetaData rsmd = data.getRsmd();
%>
<body text="black">
The table has <jsp:getProperty name="data" property="count"/> columns and <jsp:getProperty name="data" property="rowcnt"/>
rows in it.
The first column name is <%= rsmd.getColumnLabel(1) %>.
The current row is <%= rs.getRow() %>.
</pre>
</body>
</html>
Output of browser:
The table has 2 columns and 6 rows in it. The first column name is ITEMNO. The current row is
Error: 500
Location: /schedule/jsp/Trial.jsp
Internal Servlet Error:
java.lang.IllegalStateException: Response has already been committed
java.lang.Throwable(java.lang.String)
java.lang.Exception(java.lang.String)
java.lang.RuntimeException(java.lang.String)
java.lang.IllegalStateException(java.lang.String)
void org.apache.tomcat.core.HttpServletResponseFacade.sendError(int, java.lang.String)
void org.apache.jasper.runtime.JspServlet.unknownException(javax.servlet.http.HttpServletResponse, java.lang.Throwable)
void org.apache.jasper.runtime.JspServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
void javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void org.apache.tomcat.core.ServletWrapper.handleRequest(org.apache.tomcat.core.Request, org.apache.tomcat.core.Response)
void org.apache.tomcat.core.ContextManager.service(org.apache.tomcat.core.Request, org.apache.tomcat.core.Response)
void org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(org.apache.tomcat.service.TcpConnection, java.lang.Object [])
void org.apache.tomcat.service.TcpConnectionThread.run()
void java.lang.Thread.run()
Error is being thorwn on the statemnt:
The current row is <%= rs.getRow() %>.
Can anyone help with this?
Thanks in advance.Hi beattris,
No I dont close the rs and conn objects.
The relevant method of my bean is :
public void processQuery() throws Exception{
try{
Class.forName(getDrivername());
conn = DriverManager.getConnection(getUrl(),getUsername(),getPassword());
st = conn.createStatement();
rs = st.executeQuery(getQuery());
rsmd = rs.getMetaData();
int columncount = rsmd.getColumnCount();
int rowcount = 0;
setCount(columncount);
while(rs.next()){
rowcount++;
setRowcnt(rowcount);
}catch(Exception e){
throw e;
I did some searching on the internet for this error and found that it is tricky one and so far I havent found a way to correct it.
The link i went to were:
http://developer.java.sun.com/developer/Books/ProJSP/Chap19.pdf
and
http://archives2.real-time.com/rte-tomcat/2000/Jun/msg02490.html
Well, I hope I get some answers soon.
Thanks. -
BEAN : Bean included in JSP Page
Hi ,
I had developed a web-application in that I had included a bean in a JSP code by using the following
<jsp:useBean id="testbean" scope="session" class="path.test" />
now the problem is some times when we click on that particular JSP page where this bean is included the screen instead of generating the jsp page it gives a complete path of the bean location as specified in the JSP ( i.e ) "path.test" .
When I click the refresh button then the page get's loaded properly.
This issue taken place rarely but it's very important to solve this and it happens in all the JSP pages wherever I had included a bean but only sometimes .
Why so??? and help me to solve this problem
Server: Apache � Tomcat 5.0
thanks in advanceYou are absolutely correct. All your java classes should be in packages.
I actually think its a java limitation introduced in Java 1.4 - they no longer allow access to the unnamed package.
For full details check out: http://developer.java.sun.com/developer/bugParade/bugs/4361575.html
My suggestion: include all your beans in packages. Its not that hard is it?
Cheers,
evnafets -
Two managed beans in same jsp page
Hello
First this could be a stupid question, but i just can't find a solutions on this problem.
I wondering that could it be a two managed beans in same jsp page, here is a example:
index.jsp
<t:commandLink disabled="#{listBean.currentPage == 1}" id="previous2" type="button" immediate="true" style="font-size:small" action="#{listBean.previousPage}">
<h:outputText value="Edellinen" id="prev"/>
</t:commandLink>
<t:commandLink disabled="#{listBean.currentPage == listBean.totalPages}" id="next2" type="button" immediate="true" style="font-size:small;" action="#{listBean.nextPage}">
<h:outputText value="Seuraava" id="next"/>
</t:commandLink>
then i have a dataTable like this:
<t:dataTable value="#{customerListBean.customerBeans}"
binding="#{customerListBean.dataTable}" preserveDataModel="true" style="text-align:left">
My problem is that when i push a commandLink it doesn't refresh a dataTable. Does anyone know a solution here or is this just a impossible way to do it?
Thanks for help.when i push nextPage (commandLink) it's call action
and count a new range of dataset and after that it's
calls a method which is declared on subClass and that
method get a new data of database on given params.
and put it on DataTable.
So listBean is upper class and customerListBean
extends on ListBeanNo, it doesn't work that way as you expected. You have created two independent instances. They doesn't communicate automatically with each other or so. Just use one CustomerListBean instance and call the inherited methods of ListBean on the #{customerListBean} managed bean instance. -
How to call the form bean value on jsp withthe help of jstl tag
hi
all friends
i am working in struts & i use jstl tag in jsp. i have one problem rise is how to call the form bean value in jsp page by using jstl tag.
i now how to retrive the value through jsp:logic
eg. <logic:empty name="userListForm" property="users">
NO USER FOUND
</logic:empty>
see * userListForm mean formbaen name.
* users means collection object.
so how can i write above e.g in jstlYou use the jstl core:if or core:choose combined with the EL:
<c:if test="${empty users.userListForm}">
NO USERS FOUND
</c:if>I suggest you lookup the jsp expression language (EL) using google, it's very powerful. -
Hi all
I have a bean that I want to use in two JSP's. When I use it the first time it works fine but for the second JSP it returns a NullPointerException. I have my scope as "application".
In my JSP I am calling the bean as such:
<jsp:useBean id="abc" scope="application" class="ABC" />
<%
ABC bean = (ABC)session.getAttribute("abc");
%>
Please assist me with this.
ThanxI thought <jsp:useBean id="abc" scope="session" class="ABC" />and<%
ABC abc = (ABC)session.getAttribute("abc");
%>do the same thing...!!!!! Am I wrong..?
Getting back to the problem. One reason, I can think about, causing a NullPointerException may be because the session attribute is not set previously. Do you have piece of code somewhere in the servlet or before which sets the attribute in the session.?
Some thing like session.setAttribute("abc", new ABC()); -
Hi here's my bean
import java.util.*;
public class leaveChange extends Object implements java.io.Serializable
String Name;
String Grade;
String Pattern;
int numDays;
Date startDate;
Date endDate;
Now to use this bean in my JSP page what do I do ?
I tried
<%@ page import="leaveChange"%>
but got following error
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Devannualleave\newDev\advancedOptions_jsp.java:8: '.' expected
[javac] import leaveChange;
[javac] ^
[javac] 1 error
Thanks in advanceUpdate
changed Bean class to
package test;
import java.util.*;
public class leaveChange extends Object implements java.io.Serializable
String Name;
String Grade;
String Pattern;
int numDays;
Date startDate;
Date endDate;
JSP File
<%@ page import="test.leaveChange" %>
and have in my WEB-INF/classes/test
my Bean Class
but get the following error
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Devannualleave\newDev\advancedOptions_jsp.java:8: package test does not exist
[javac] import test.leaveChange;
[javac] ^
[javac] 1 error
Any help ? -
Defining the path for the use of beans in a JSP
Hello,
I would like to use a bean in a JSP file, via the <jsp:usebean> directive.
I didn't find any property (weblogic property) which could define the path
to the directory of my beans classes.
So :
1) i have put the path of this directory in the weblogic classpath in the weblogic
start script.
2) i made the same with the java classpath.
Both solutions don't work at all.
Any suggestion would be appreciated.
Thanks in advance.
We use the \weblogic\myserver\serverclasses for beans..
of course we pack beans into jar files, and these jar files are included into
the wls classpath..
"Sylvain R." <[email protected]> wrote:
>
>Hello,
>I would like to use a bean in a JSP file, via the <jsp:usebean> directive.
>I didn't find any property (weblogic property) which could define the
>path
> to the directory of my beans classes.
>So :
>1) i have put the path of this directory in the weblogic classpath in
>the weblogic
>start script.
>2) i made the same with the java classpath.
>
>Both solutions don't work at all.
>
>Any suggestion would be appreciated.
>Thanks in advance.
>
-
what's the syntax for declaring two different beans in a JSP ?
can we have two <jsp:useBean...> tags ??
<jsp:useBean id="view" type="org.ab.GenericView" scope="request"></jsp:useBean>You can have include many <jsp:useBean> tags. Use different id/scope combinations.
e.g.
<jsp:useBean id="view" type="org.ab.GenericView" scope="request"></jsp:useBean>
<jsp:useBean id="anotherview" type="some class" scope="request"></jsp:useBean>
<jsp:useBean id="thirdid" type="some class" scope="session"></jsp:useBean> -
Hi..
Can anybody plz help me..
I already deploy the new JPDK Jan 2003.
It's works fine in the Portal.
Just, i don't understand, where they put the java files(bean) related?
For example..the Lottery (lotto.jsp)
it called this bean..
"<jsp:usebean id = "picker" class = "oracle.portal.sample.devguide.lottery.LottoPicker" scope = "page" />"
but, when i searched in the Server, i cannot find this LottoPicker.java.....
Pls help me, it is urgent..Hi,
All the bean files are in samplev2.jar at %OC4J_HOME%/j2ee/home/applications/jpdk/jpdk/WEB-INF/lib. If you extract the zip you will see all the class files for samples in JPDK.
btw, as per J2EE container specification, the default location for any java class file (i.e. '.class' files) is WEB-INF/lib (packaged as a jar) or inside WEB-INF/classes as individial class files (with their complete package structure)
Regards,
Abhinav -
Tracking execution of bean used in jsp
hi,
i'm using a bean to get records from a database.
but i'm not sure if the bean is actually getting called and executed from the jsp file.
i'ld like to get the step by step details about the execution of bean when it is called.
is this possible?
how?hi,
i'm using a bean to get records from a database.
but i'm not sure if the bean is actually getting
called and executed from the jsp file.
i'ld like to get the step by step details about the
execution of bean when it is called.
is this possible?
how?I presume that you have an idea how to code in JSP, so here goes
You create an instance of your bean by doing
<jsp:useBean id="UseMe" class="YourBean"/>
<%
System.out.println("Calling the bean");
String result = useMe.methodToBeCalledInYourBean();
//Assuming that the method is returning the data in a string format
System.out.println("Result recieved from bean");
%>For knowing what is happening I suggest you put SOP's in your bean methods.
For further queries post some code and the actual problem that you are facing.
Regards, -
Impossible to access a bean from a JSP in NES 4.0
We are trying to use a bean in a JSP using the common tag <jsp:useBean id="... /> in a Netscape Enterprise Server 4.0.
Always we obtain the same error: "JSP compilation error: java.lang.Exception: JSP parse error (line 43) - Incomplete tag ending of /jsp:useBean". Someone can help us?
Thanks.Check NAS4.0 supports jsp 0.92 specs?
use this tag...
<USEBEAN name="..." type="..." lifespan="..." >
</USEBEAN> -
Embedding a bean in a jsp application
guy's
i am trying to use a bean in my jsp page ,but i dont know how to deploy my bean with my page ,so please tell me how to deploy my bean with my page step by step.
thanks
johnPut your bean / class into a package :
WEB-INF/classes/yourPackage/yourClass
Then in your jsp header
<jsp:useBean id="yBean" class="yourPackage.yourClass" scope="session">
To use the bean in jsp
yBean.getYourMethod();
Theres loads of stuff in these forums and on google if you get stuck...... -
Sharing data between a bean and a jsp
I have a bean that is being used as a helper class for a jsp page. I can call functions in the bean and display what is returned but I can't test the state of the bean in the jsp page. Is this possible?
my code is below:
jsp: a form posts info to this page
<HTML>
<BODY>
<jsp:useBean id='portal' class='portal.portal'/>
<%-- set the username and password --%>
<jsp:setProperty name="portal" property="*" />
<jsp:getProperty name="portal" property="dbconnection"/>
<Center>
<H1>Welcome to the Portal
<jsp:getProperty name="portal" property="firstName"/>
</H1>
<br>
<table border="0">
<%-- while loop grabs all the services --%>
<%-- case tests for special services (links) --%>
<%
String url = "";
int ServiceID = 0;
//I CAN'T PULL THE VALUES FOR THESE VARIABLES SO THE WHOLE WHILE LOOP IS SKIPPED!
while (url.length() != 0)
switch (ServiceID)
case 69:
%>
<tr valign="top" height="45">
<td>
<center>
" TARGET="new_window"><IMG SRC="images\MEDS TAPE LOG.gif" BORDER=white></A><br>
</center>
</td>
</tr>
<%
break;
case 41:
%>
<tr valign="top" height="45">
<td>
<center>
<A HREF="<jsp:getProperty name="portal" property="url"/>" TARGET="new_window"><IMG SRC="images\Lan Support Website.gif" BORDER=white></A><br>
</center>
</td>
</tr>
<%
break;
case 1:
%>
<tr valign="top">
<td>
<center>
<form name="loginfrm" action="http://204.104.185.139/pls/WLOG/login.ValidateUser" method="post" target=_parent>
<INPUT TYPE=hidden NAME=TXTUSERNAME VALUE="<jsp:getProperty name="portal" property="name"/>">
<INPUT TYPE=hidden NAME="TXTPASSWORD" VALUE="<jsp:getProperty name="portal" property="password"/>">
<input TYPE="submit" VALUE="<jsp:getProperty name="portal" property="serviceName"/>" style="width: 120px;" >
<input type="reset" name="reset" value="">
</Form>
</center>
</td>
</tr>
<%
break;
default:
%>
<tr valign="top">
<td>
<center>
<Form method='post' action='<jsp:getProperty name="portal" property="url"/>' name='loginfrm'>
<INPUT TYPE=hidden NAME="TXTPASSWORD" VALUE="<jsp:getProperty name="portal" property="password"/>">
<INPUT TYPE=hidden NAME="TXTUSERNAME" VALUE="<jsp:getProperty name="portal" property="name"/>">
<INPUT TYPE=hidden NAME="firstname" VALUE="<jsp:getProperty name="portal" property="firstName"/>">
<INPUT TYPE=hidden NAME="lastname" VALUE="<jsp:getProperty name="portal" property="lastName"/>">
<INPUT TYPE=hidden NAME="id" VALUE="<jsp:getProperty name="portal" property="userID"/>">
<INPUT TYPE=hidden NAME="role" VALUE="<jsp:getProperty name="portal" property="roleID"/>">
<input type='submit' name='submit' value='<jsp:getProperty name="portal" property="serviceName"/>'>
</Form>
</center>
</td>
</tr>
<%
break;
%>
<jsp:getProperty name="portal" property="nextForm"/>
<%
%>
</table>
</Center>
</Body>
</Html>
here is the bean:
//bean for portal
package portal;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.Enumeration;
import java.sql.*;
import java.util.*;
public class portal {
private ResultSet userInfo;
private Statement stmt;
private String pw;//password from the database
private String FirstName;
private String LastName;
private String UserName=""; //network login name
private String UserPassword="";//password supplied by the form
private int UserID; // temp variable while pulling the services from the databases
private int RoleID; // temp variable while pulling the services from the databases
private String ServiceName=""; //temp variable while pulling the services from the database
private int ServiceID;
private String url ="";
//String Message=""; //testing
private String Message2=""; //string that sends the correct html back to the jsp
public int getServiceID(){
return ServiceID;
public void setName(String Name){
UserName = Name;
public String getName(){
return UserName;
public void setPassword(String Password){
UserPassword = Password;
public String getPassword(){
return UserPassword;
public String getFirstName(){
return FirstName;
public String getLastName(){
return LastName;
public String getUrl(){
return url;
public int getUserID(){
return UserID;
public int getRoleID(){
return RoleID;
public String getServiceName(){
return ServiceName;
public String getDbconnection() {
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
DriverManager.setLoginTimeout(60);//time out after 1 min.
Connection con = DriverManager.getConnection("jdbc:odbc:Portal");
stmt = con.createStatement();
String query = "SELECT EMP_TABLE.EMP_PASS, MGR_SERVICES.SERVICE_ID,";
query = query +" MGR_SERVICES.DEFAULT_URL, EMP_TABLE.EMP_USER_ID, *";
query = query +"FROM (EMP_TABLE LEFT JOIN MGR_USER_SERVICES ON";
query = query +" EMP_TABLE.EMP_USER_ID = MGR_USER_SERVICES.USER_ID)";
query = query +" LEFT JOIN MGR_SERVICES ON MGR_USER_SERVICES.SERVICE_ID =";
query = query +" MGR_SERVICES.SERVICE_ID WHERE (((EMP_TABLE.EMP_LAN_ID)='" + UserName+ "'))";
//String query = "SELECT EMP_TABLE.EMP_PASS, MGR_SERVICES.SERVICE_ID,";
//query = query +" MGR_SERVICES.DEFAULT_URL, EMP_TABLE.EMP_USER_ID, *";
//query = query +"FROM (EMP_TABLE LEFT JOIN MGR_USER_SERVICES ON";
//query = query +" EMP_TABLE.EMP_USER_ID = MGR_USER_SERVICES.USER_ID)";
//query = query +" LEFT JOIN MGR_SERVICES ON MGR_USER_SERVICES.SERVICE_ID =";
//query = query +" MGR_SERVICES.SERVICE_ID WHERE (((EMP_TABLE.EMP_LAN_ID)='landwla'))";
//String query = "SELECT * FROM EMP_TABLE WHERE EMP_LAN_ID ='landwla'";
userInfo = stmt.executeQuery(query);
if(userInfo.next())
pw = userInfo.getString("EMP_PASS");
if (UserPassword.equals(pw))
//Message = "Your logged in";
//Message = Message + "Luke you sly devil";
FirstName = userInfo.getString("EMP_FIRST");
LastName = userInfo.getString("EMP_LAST");
UserID = userInfo.getInt("EMP_USER_ID");
RoleID = userInfo.getInt("ROLE_ID");
url=userInfo.getString("DEFAULT_URL");
ServiceName = userInfo.getString("SERVICE_NAME");
ServiceID = userInfo.getInt("Service_ID");
else
Message2 = "<Script Language=JavaScript>";
Message2 = Message2 + "alert('Your Password Information is incorrect');";
Message2 = Message2 + "window.location.href = 'Login.html'";
Message2 = Message2 + "</Script>";
else
Message2 = "<Script Language=JavaScript>";
Message2 = Message2 + "alert('Your Login Information is incorrect');";
Message2 = Message2 + "window.location.href = 'Login.html'";
Message2 = Message2 + "</Script>";
catch (InstantiationException i)
{return (i.toString());}
catch (ClassNotFoundException c)
{return (c.toString());}
catch (SQLException sql)
{return (sql.toString());}
catch (Exception e)
{return (e.toString());}
return Message2;
public String getNextForm() {
try
url="";
ServiceName="";
if(userInfo.next())
url=userInfo.getString("DEFAULT_URL");
ServiceName = userInfo.getString("SERVICE_NAME");
RoleID = userInfo.getInt("ROLE_ID");
ServiceID = userInfo.getInt("Service_ID");
catch (SQLException sql)
{return (sql.toString());}
return Message2;Of course you can.
<%
String url = protal.getUrl();
%> -
Using an attribute set in a servlet as a bean in a JSP
Say, I have saved an attribute in any scope in a servlet or its helper class using setAttribute("xyz", someObject).
* Would I be able to access this attribute in a subsequent JSP using <jsp:getProperty name="xyz" property"someProperty" /> *
The reverse works true ie. setting the attribute first as a bean in a jsp and den accessing it using getAttributLakshminarayanan,
Actually, there are 2 ways to share data between WD components:
1. Context mapping
2. Combo of parameters to methods / parameters in events.
Say, you want to synchronize your 2 toolbars. You may declare some method(s) to alter state in "toolbar" component interface and some event(s) about state update. Now main component has to subscribe to this event from every component usage and invoke method in other component usage to synchronize state.
With context mapping you may achieve state synchronization automatically. Also method/event pair will look plain ugly if you have a lot of parameters or complex structures.
Valery Silaev
EPAM Systems
http://www.NetWeaverTeam.com
Maybe you are looking for
-
hi, when i am try to move stock to the ware house, in goods receipt it throws .Error during search for WM movement type (921 B ) Message no. L9005 i am using the movement type 101.i miss any configuration in it .if so tell me in detail.my reqir
-
MS IIS 4.0 and MS Exchange 5.5 vs IIS 3.0 and 5.5
Has anyone had any luck running IIS 4.0 with Exchange 5.5? The documentation for the install says that IIS 3.0 should be installed with Exchange 5.0. It doesn't seem to be working and we are hoping we won't have to re-install in order to fix the foll
-
Hi, Can i help me to send a workflow SAP to an user E-mail LOTUS. How can i do that. Best regards.
-
After the latest release of iOS 8.1.2, I am not able to view videos
Hi All, After the latest release of iOS 8.1.2, I am not able to view videos from the below website: www.startv.in/episodes/santosh-discovers-the-truth/76711 Until the previous iOS version 8.1.1, there wasn't any problem. But now none of the video is
-
hi all, I have written the following script to do near analysis on road and point data type. Road table has 36629 road and point table has 10834 points and want to identify all points which are within one km of the road. Query is running even after 2