Accessing  bean in servlet

hi to all,
i created a simple bean for login access that has getter and setter method...
I am trying to access the bean in a servlet .. i got error....
my bean code is ...
simple login page
<form method="post" action="/BeanServlet">
user Name :
<input type="input" name="username" >
Password :
<input type="password" name="password" >
<input type="submit" value="submit" >
</form>
package use;
public class UserData {
String username;
String password;
public void setUsername( String value )
username = value;
public void setPassword( String value )
password = value;
public String getUsername() { return username; }
public String getPassword() { return password; }
please fill in the Servlet code is
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
UseData ud = (UserData) session.getAttribute();
????? what comes here
out.println(ud.getPassword(););
out.println(ud.getUsername());

sorry kannankalli, but this is what i understood from your question, that you want to take the information of a form from a servlet,,
and this is the servlet code:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class Servlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
public void init(ServletConfig config) throws ServletException {
super.init(config);
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,IOException {
String retrievedUserName = request.getParameter("userNameField");
String retrievedPassword = request.getParameter("passwordField");
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet</title></head>");
out.println("<body>");
out.println("<p>The userName is: </p>" + retrievedUserName);
out.println("<p>The password is: </p>" + retrievedPassword);
out.println("</body></html>");
out.close();
notice request.getParameter("userNameField"); the userNameField is the same name as the textField in the html page, and so the password...
I hope i reached your point..(^_^);

Similar Messages

  • Servlet cannot access bean

    Hi all,
    I am having some problems accessing JavaBeans from my servlets, but I can access them from my JSP page(i used the import command, <%@ page import="servlets.myBeans.login.User" %>, and it works).
    I have placed my User bean in the following package
    \webapps\ROOT\WEB-INF\classes\servlets\myBeans\login
    Here's the java code for User Bean
    package servlets.myBeans.login;
    * A simple Java Bean for users.
    public class User implements java.io.Serializable{
    private String username = null;
    private String password = null;
    public User() {}
    public User (String u, String p) {
         username = u;
         password = p;
    public String getUsername() {
         return username;
    public void setUsername(String username) {
         this.username = username;
    public String getPassword() {
         return password;
    public void setPassword(String password) {
         this.password = password;
    public String toString() {
         return username + ":" + password;
    This compiles and creates a class file.
    My servlet LoginControlServlet is in the following path
    \webapps\ROOT\WEB-INF\classes\servlets
    when I try to compile this servlet i get the following errors
    C:\jakarta-tomcat-4.1.1.12-LE\jakarta-tomcat-4.1.24-LE-jdk14\webapps\ROOT\
    WEB-INF\classes\servlets\LoginControlServlet.java:18:
    cannot resolve symbol
    symbol : class User
    location: class servlets.LoginControlServlet
    User up = (User)session.getAttribute("up");
    ^
    C:\jakarta-tomcat-4.1.1.12-LE\jakarta-tomcat-4.1.24-LE-jdk1\webapps\ROOT
    \WEB-INF\classes\servlets\LoginControlServlet.java:18:
    cannot resolve symbol
    symbol : class User
    location: class servlets.LoginControlServlet
    User up = (User)session.getAttribute("up");
    ^
    C:\jakarta-tomcat-4.1.1.12-LE\jakarta-tomcat-4.1.24-LE-jdk1\webapps\ROOT
    \WEB-INF\classes\servlets\LoginControlServlet.java:27:
    cannot resolve symbol
    symbol : class User
    location: class servlets.LoginControlServlet
    up = new User(user,pass);
    ^
    3 errors
    I have already included the \webapps\ROOT\WEB-INF\classes in my class path
    infact, I have even included \webapps\ROOT\WEB-INF\classes\servlets and
    \webapps\ROOT\WEB-INF\classes\servlets\myBeans\login in my classpath.
    Any ideas, as to why I am having the above errors.
    thanks,
    manish

    I think it's pretty much got to be a compile time classpath problem. Either your bean is compiling to a funny place, or you classpath is wrong when you compile the servlet. Probably the latter if your jsp picks it up OK.
    The entry in the classpath should be
    <tomcat directory>/webapps/ROOT/WEB-INF/classes
    Check the syntax carefully.
    putting package directories on your classpath can only confuse things.
    Make sure that ...../webapps/servlets/myBeans/login/User.class exists.

  • Access of JSF Beans from Servlet Filter

    Is there any way how can I access session JSF beans from servlet filter?
    I need to check certain value of JSF bean stored in session scope in my filter.
    Thanks
    ferdo

    Frank,
    I am not sure about phase listener, this is the whole situation:
    as I am not using Container Managed Security with my JSF, after I do sucessfull login into application, I need to store some information into the session scope (user etc) and in the servlet filter I need to find out if the user is connected.
    I was trying to put such info into Servlet Session directly in my bean via External Context and reading the info in Filter.
    This is working fine when my application is running locally (jdev oc4j) but once deployed into Application server, when user login first time, user information is somehow removed from the session, and cannot figure out why.
    So I was thinking to try another approach, to find out from servlet filter if JSF bean value is set or not.
    Any other suggestions? Do not want to swicth to Container Manages Security now.
    ferdo
    null

  • Portal runtime error: Cannot access bean property

    Dear all,
    Does anybody have a clue what problem might couse the <b>Portal Runtime Error</b> described below?
    It does seem to occur when a second user wants to access the <b>Component</b>.
    <b>Portal Runtime Error</b>
    An exception occurred while processing a request for :
    iView : pcd:portal_content/com.xxxxx.luminaires/com.xxxx.iviews/Quotations/EasyQuote
    <b>Component</b> Name : EasyQuoteDemo.EasyQuoteComponent
    Tag tableView attribute model: Cannot access bean property quotationHeader.CurrentTableModel in page context.
    Exception id: 04:50_21/09/04_0070
    See the details for the exception ID in the log file
    Thxs in advance
    Joost

    Hi Dominik,
    Having a closer look at the problem, we found it is not the number of users.
    It seems our JAVA components keeps the conenctions with SAP open and reopens a new one every time we start the component.
    If we finished solving the problem, I will publish the solution.
    Greetings,
    Joost

  • Access EJB from Servlet that in different archive?

    <font class="mediumtxt">package kyro.ejb.session;
    import javax.ejb.*;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    @Stateless(name="StandAlone")
    @Remote(StandAlone.class)
    public class StandAloneBean
    implements StandAlone, StandAloneLocal
    public StandAloneBean() {
    public String sayHello() {     
    return "sayHello";
    I want to access ejb from servlet that .war and .jar not in single .ear. I want to try that just with annotation not xml descriptor cause is easy to understand for me. I use Glassfish. But i can't lookup that ejb. How can i lookup that ejb with jndi? Can't you give me example of servlet to access that? I not use JNDI.properties, are that caused i can't access my ejb? I just thing .war and.jar in one server, are i have to used JNDI.properties. can you explain how to use JNDI.properties in servlet or separate file?
    </font>

    But i can't lookup that ejb. How are you trying and what exception is occurring?
    How can i lookup that ejb with jndi? [https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html|https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html]
    m

  • Strange behavior with entity beans and servlets in a cluster

    We have 2 WebLogic 4.5.1 servers in a cluster with none of the Service
              Packs installed. When a client uses the deployed entity beans or
              servlets they work every other time. The times they do not work nothing
              happens. No exceptions, no responses to the client ( i.e. HTTP 404s ),
              nothing. I suspect something in the cluster setup since we do not have
              these same problems on non-clustered entity beans or servlets. We have
              made sure all the entity beans have the Shared Database flag set on and
              added the delayUpdatesUntilEndOfTx false to the enviroment of the DD.
              That didn't fix the problem. Any ideas?
              Thanks in advance,
              Dallas Dempsey
              DEM - Houston, TX
              

    Do you have log files?
              - Prasad
              Chris Dempsey wrote:
              > We have 2 WebLogic 4.5.1 servers in a cluster with none of the Service
              > Packs installed. When a client uses the deployed entity beans or
              > servlets they work every other time. The times they do not work nothing
              > happens. No exceptions, no responses to the client ( i.e. HTTP 404s ),
              > nothing. I suspect something in the cluster setup since we do not have
              > these same problems on non-clustered entity beans or servlets. We have
              > made sure all the entity beans have the Shared Database flag set on and
              > added the delayUpdatesUntilEndOfTx false to the enviroment of the DD.
              > That didn't fix the problem. Any ideas?
              >
              > Thanks in advance,
              > Dallas Dempsey
              > DEM - Houston, TX
              

  • Help:accessing beans method

    hello
    i have made one application in which i have made two beans under different packages. i am trying to access beans through jsp pages. i am able to access beans and their methods but when i add new method in bean and tried to access that method with different new jsp page say page1.jsp. I am not able to access new method though i am able to access old methods of same beans with this new jsp page. then i made new bean and copied that method in this new bean . then i tried to access that method of this new bean with page1.jsp and i am able to access it can any body guide me what is the reason for this. i want to run this method in old beran rather than new bean
    my directory structure is:
    projectlms---main folder
    addstream---old jsp page
    page1---new jsp page
    web-inf/classes
    com-------main packageof beans
    ProgramManager----sub package of classes
    bean1--------old bean
    new bean------new bean just for testing
    now the problem is that i want to add one more method to bean1 and want to access it through pag1.jsp
    but i am not able to access it and same method when i take to new bean i am able to access that method through page1.jsp
    but i am able to access old methods of bean1 through page1.jsp
    thanks
    regards
    vivek

    Could be a caching issue.
    Wipe out the COMPILED jsps and try again.

  • Using java bean in servlet

    Hi,
    I have a problem in getting the values from simple bean to servlet. The project has one html form. When the user click on the submit button one jsp will be invoked which calls a bean program to validate the user data for required fields. Based on the result, jsp program forward the control to a servlet which stores the data in a database. Otherwise another jsp is called to inform the user to fill in the required data.
    My problem is how to send the data from bean to servlet?
    The snippet of jsp that calls bean is like this :
    <%!
    %>
    <jsp:useBean id="formHandler" class = "subFormBean" scope="request">
    <jsp:setProperty name="formHandler" property="*"/>
    </jsp:useBean>
    <%
    if (formHandler.validate()) {
    %>
    <jsp:forward page="subscriberRegistration"/>
    <%
    } else {
    %>
    <jsp:forward page="retry.jsp"/>
    <%
    %>
    And the snippet of the bean is like this :
    public boolean validate() {
    boolean bool=true;
    if (subname.equals("")) {
    errors.put("subname","Please enter your Name");
    subname="";
    bool=false;
    public subFormBean() {
    subname="";
    public String getSubName() {
    return subname;
    public void setSubName(String sname) {
    subname =sname;
    The servlet which is to receive the data is like this :
    public class subscriberRegistration extends HttpServlet{
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    subFormBean sfb = new subFormBean();
    sfb.setSubName(subname);
    But I'm getiing error while trying to compile the servelet saying that no variables found - sfb, subname etc.
    Please let me know how to invoke the bean from servlet. I want to use servlet to instead of jsp to insert records into database. How can i do this? Please help me. Thanks in advance.

    Hi Tolls,
    Sorry, I'll give a bigger snippet of the prog.code below :
    public class subscriberRegistration extends HttpServlet{
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    subFormBean sfb = new subFormBean();
    sfb.setSubName(subname);
    sfb.setSubAddress(subaddress);
    sfb.setSubCity(subcity);
    sfb.setSubState(substate);
    sfb.setSubCntry(subcntry);
    sfb.setSubPin(subpin);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    Class.forName("oracle.jdbc.driver.OracleDriver");
    connection = DriverManager.getConnection(connectionURL,"scott","tiger");
    stmt = connection.createStatement();
    rs = stmt.executeQuery("SELECT subid_seq.NEXTVAL FROM DUAL");
    while(rs.next()) {
    String subno = rs.getString("NEXTVAL");
    PreparedStatement pst = connection.prepareStatement("insert into eps_subscriber(eps_subno, eps_subname, eps_subaddress, eps_subcity, eps_substate, eps_subcntry, eps_subpin, eps_subphno, eps_subemailid, eps_subuserid, eps_subpwd) values(?,?,?,?,?,?,?,?,?,?,?)");
    pst.setString(1,subno);
    pst.setString(2,sfb.subname);
    pst.setString(3,sfb.subaddress);
    pst.setString(4,sfb.subcity);
    pst.setString(5,sfb.substate);
    pst.setString(6,sfb.subcntry);
    pst.setString(7,sfb.subpin);
    I'm validating the form data in beans program. Servlet is used to insert records into the database. So, i'm trying to capture data from the bean. How to capture the data from the bean to servlet? Or should I get it from the form fields directly? The servlet worked well when data was captured directly from html form fields. Please help me to fix this. Thanks in advance.

  • Cannot access directory javax/servlet

    I am having a problem getting started here with Borland JBuilder 8 SE.
    I have Tomcat installed and it runs fine with the servlets/jsp pages I ran from the index page when you first install Tomcat.
    I am running windows 2000. When I installed JBuilder the Java 2 SDK v1.4.1 was installed with it. I have run applets... java.exe is located in the jbuilder folder, don't know if this is a problem. I have set my JAVA_HOME environment variable to point to the bin folder in the 1.4.1 java.exe location.
    I am following a book that works with servlets and jsp primarily. When I typed in my first servlet that I copied from the book, JBuilder gives me a document location error:
    cannot access directory: javax/servlet at line...
    it is pointing to my import statement: "import javax.servlet.*;" and "import javax.servlet.http.*;".
    I have tried to add the servlet.jar file to my project but the results are the same.
    Can anybody give me a hand?
    thanks,
    Rob

    The fastest way for JBuilder to see it is just to create a library for servlet.jar and add it to the project.
    Tools->Configure Libraries->New
    Then browse to the location of the servlet.jar and call the library SERVLET.
    Project->Project Settings->Required Libraries
    Then add this library and try to build your project.
    JBuilder will automatically add it to the classpath when it compiles the project that way.

  • Where cannot i access class javax.servlet

    i dont kwon whta happend this: "OutputFilterBase.java": Error #: 302 : cannot access class javax.servlet.ServletResponse; java.io.IOException: class not found: class javax.servlet.ServletResponse at line 62, column 22
    please help me
    thanks

    You need a servlet engine for servlets. Like resin, tomcat etc. Then add it to classpath.
    Andreas

  • Send data from bean to servlet and get results back to bean

    Hi,
    I'm new to this helpful forum and, as long as I'm practicing with JFS and Java Beans and Servlets, I really need some help about the following crappy issue.
    I made a JSP login page called "LoginPage.jsp" (using "Visual Web JSF Page" tool in NetBeans 6.0), and the action associated to the "Login" button pression is defined in the associated Java Bean "LoginPage.java":
    Code from "LoginPage.jsp":
    <webuijsf:button actionExpression="#{LoginPage.loginButton_action}" binding="#{LoginPage.loginButton}" id="loginButton" primary="true" style="height: 24px; left: 383px; top: 192px; position: absolute; width: 96px" text="Login"/>
    Code from "LoginPage.java":
    public String loginButton_action()
        if (usernameField.equals("guest") && passwordField.equals("guest")) // this control should be done by a servlet, not here!
            return "loginOK"; // this is the outcome for faces-config.xml that will lead to a "Welcome.jsp" page
        else
            return "loginERROR"; // this is the outcome for faces-config.xml that will lead to a "Error.jsp" page
    ...Now, the problem is that the username and password control should not be done by the bean itself, but by a servlet (call it "LoginServlet.java").
    In a few words, what I mean is that once the user writes username and password and presses the "Login" button, the called "loginButton_action()" forwards all the needed data to the servlet "LoginServlet.java", the servlet does the complete checks about login validity then prepares the result (it could be a string reporting "OK" or whatever else) and send it back to the bean "LoginPage.java", so that the flow can continue.
    My problem is that I absolutely don't know how to make a bean and a servlet communicate in both ways and respectively exchange data.
    Thanks in advance for any help, it will really be appreciated.

    Google for passing values in request and session.

  • Access bean(wrapper) for EJB

    How can I develop access bean(wrapper) for EJB in JDeveloper?

    Search the Internet for a product called JACOB
    JAva COm Bridge

  • Server Shows : Error in Accessing Beans

    here it shows the error as "Error in Accessing Beans".Anybody knows solutions pls give solutions for this.

    Hi Visakh,
                    Yes,The user is holding the permission as "Global User" in sql.Hope you help me in solve this issue
    Thanks, Quality Communication Provides Quality Work. http://siddiq-sharepoint2010.blogspot.in/ Siddiqali Mohammad .
    Hi siddiqali,
    According to the screenshot you posted above, the use account didn't have sufficient permission to open the report, please check the following prerequisites before you perform the action:
    You must use a report definition (.rdl) file as a data source. Importing from a report model is not supported.
    You must have permission to open the report under your Windows user account, and you must know the address of the report or the report server that hosts it. You can check your permissions by trying to open the report in a Web browser first.
    If the report opens, it confirms that you have sufficient permissions and the correct URL.
    Reporting Services must be version SQL Server 2008 R2 or SQL Server 2012. Those versions include the data feed export feature that streams report data in the XML data feed format. You can identify the report server by the Export as Data Feed option
    that appears in the report toolbar when you open the report in browser:
    For detail information, please see:
    Import Data from a Reporting Services Report:
    http://technet.microsoft.com/en-us/library/gg413491.aspx
    Regards,
    Elvis Long
    TechNet Community Support

  • Accessing Managed Session Bean in Servlet Filter

    I wrote a Servlet Filter to handle user authentication. Now I'm trying to access my Managed Session Bean in the filter in order to save the current user. Unfortunately the Session Bean is created after the Filter executes for the first time.
    I'm trying to access the Session Bean in this way:
    (SessionBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("sessionBean");
    In this case getExternalContext() is equals null.
    Is there any way to create the Session bean before the filter executes or any other ideas how to handle this?
    I already searched around the internet but couldnt figure out something.
    Thanks guys,
    Paul

    Ok, fixed it like this. Works perfect. JSF finds and uses the handmade Session Bean as well.
    if(request.getSession().getAttribute(BeanNames.SESSION_SCOPE_BEAN) == null) {
         SessionBean sessionBean = new SessionBean();
         request.getSession().setAttribute(BeanNames.SESSION_SCOPE_BEAN, sessionBean);
    }Thanks,
    Paul

  • Servlets accessing beans

    Hi,
    I know I can use
    <jsp:useBean>to create and access named Bean objects in my application from JSP. But I would like to create a named Bean object from a servlet and store it in the session scope, so that my JSPs can access this later.
    How do I instantiate a named bean in a servlet?
    Thanks!

    MyBean myBean = new MyBean();
    session.setAttribute("myBean", myBean);
    Now you can access the bean in a JSP using:
    <jsp:useBean id="myBean" scope="session" class="MyBean" />

Maybe you are looking for

  • How do I install a Dell 3000cn on my macbook air?

    I just bought my first Apple. Love it! How do I install the proper drivers to run my Dell 300cn color laser printer? Dell doesn't have a Mac driver for it. When I try to print, it throws out pages of characters.

  • Work on IMOVIE08 import

    Hi, I imported work from imovie08 via xml. At first editing worked fine. Than, because of the fact that audio was imported as two mono tracks I began to create stereo pairs (btw, is there no other way as to do that with every dammed single clip?). Al

  • Logical Standby - Application Express Recovery

    Ive asked a similar question in the following threads:- Re: Recovering Logical Standby - Non-Guarded Schemas Logical Standby - Application Express Recovery Were using 10g Logical Standby database for our reporting environment and within it we have Or

  • HT204291 How do I find what my airplay password is?

    How do I find what my airplay password is?

  • PS4 Error Code WS-37338-4

    Have someone fixad the problem. I cant even log in on psn it says My ps4 is banned. Error code ws-37338-4