How to reach public variables in a servlet from jsp

this is myclass.java servlet
public class myclass{
     public String var1,var2;
    public void method1() {
    var1="test1";
    var2="test2";
}this is my jsp page;
<%@ page import="com.xxx.albumlerim.myclass"%>
<%
myclass tester=new myclass();
tester.method1();
out.print(tester.var1);
out.print(tester.var2);
%>jsp can run the method but doesnt recognize tester.var1 and tester.var2 how can i reach this variables what i must do.?
thank you
Burak
Message was edited by:
netsonicc

I may have used the term incorrectly. Basically I meant using the <jsp:include> tag to invoke a servlet directly. Then the servlet could send the output you need. That way you could keep things more modular.
So for example -- you say you have a servlet with these values. Maybe you could add some functionality to it so if it's invoked with a particular URL, it produces output displaying these values.
Then you could use <jsp:include> to invoke that new functionality via that URL.
Just an idea.

Similar Messages

  • How to get an ArrayList Object in servlet from JSP?

    How to get an ArrayList Object in servlet from JSP?
    hi all
    please give the solution for this without using session and application...
    In test1.jsp file
    i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
    After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
    ---------Code----------
    <jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
    <jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
    <%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
    <jsp:setProperty name="payment" property="strDate" param="expirationDate" />
    <jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
    <%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
    <jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
    <jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
    <jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
    <%
    lis.add(payment);
    %>
    </jsp:useBean>
    <%
    request.setAttribute("lis1",lis);
    %>
    -----------Code in JSP-----------------
    In testServlet.java
    i tried to get the arraylist object in servlet using request.getAttribute
    But I unable to get that arrayObject in servlet.....
    So if any one help me out in this, it will be very helpfull to me..
    Thanks in Advance
    Edward

    Hi,
    Im also facing the similar problen
    pls anybody help..
    thax in advance....
    Litty

  • 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 do I send E-Mail using Servlet or JSP?

    Hi friends,
    Anybody can you please tell me how do I send an email in Servlet or JSP?
    Do I need any special configuration to check in my server space?
    I am puzzled because after surfing on net, I found that some people sending email with Javamail and Activation API
    and some people sending email using import="sun.net.smtp.SmtpClient";Please give me some simple direction or any working code if possible.
    Thanking u,
    ---Sujoy

    What you need is a working SMTP account to be able to send email, that is accessible from the server. If you have that, simply use JavaMail.

  • Error in accessing servlet from JSP

    Hello everybody,
    When I access a servlet from a JSP page,I am getting the following error message :
    Error 404--Not Found
    From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
    10.4.5 404 Not Found
    The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
    If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.
    I am using Weblogic 7.0 and my web.xml code is as follows:
    <web-app>
    <servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/TestServlet</url-pattern>
    </servlet-mapping>
    </web-app>
    I am accessing the servlet from a javascript function in my JSP page.
    I am quite new to the Java technology. So any help in this regard would be highly appreciated.
    Thanks in advance,

    The form action event is in a javascript function. I am sorry I mentioned that I am accessing this servlet from JSP. Actually,this servlet is accessed from an HTML document.
    The following is the javascript code:
    <script language="javascript">
    function lfnCallNext()
         alert("In the function");
         frmMain.method="POST";
         frmMain.action="/TestServlet";
         frmMain.hidChoice.value="GetList";
         frmMain.submit();
    </script>
    And this function is called from an hyperlink as follows:
    Work with Employee Database
    Thanks,

  • Wot all ways are there to call servlet from jsp

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanx

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanxhi here are few ways... to call servlet from jsp...
    these are just generic syntax.
    Form:     
    <form action="ServletPath">
    Link:     
    Directives & Action tags :
    <%@ page import="ServletPath" %>
         <%@ taglib uri="ServletPth" %>
         <jsp:include page="ServletPath">
         <jsp:forward page="ServletPath">
         <jsp:useBean class="ServletPath"> (Not sure about this useBean)
    hope you got your answer.
    regards,
    immu

  • Using public variables in a servlet

    Hi, I have a public variable "CustID" in my servlet. Note that is a public member variable and not a static variable.
    In the doPost() method, I am trying to use the custId field.
    Pls. look at the code below. I want to know that in a multi-user environment since the custId field is defined at Servlet level as a member variable, is there a chance for this variable to be corrupted and I fire a wrong query ???
    Awaiting your answers
    public class QWCustomerServlet extends HttpServlet
    public boolean debug = false;
    public QWFieldList fieldList = new QWFieldList();
    public String custID = null;
    public doPost(HttpServletRequest req, HttpServletResponse res)
    HttpSession session = null;
    if ( (session = request.getSession(false))!= null){ 
    custId = session.getAttribute("cid");
    String query = "select * from customer where cust_id=" + custId;
    Statement stmt = conn.createStatement();
    stmt.executeQuery(query);
    }

    Yes. There is only one instance of a servlet and all requests thread through it. Don't use instance variables unless you want all threads to share (usually in a read-only manner such as a reference to a resource). In your example, move the custId declaration inside doPost and it will be thread-safe.

  • How to create thumbnail images on the fly from JSP or servlet?

    Hi all,
    Iam new to this forum. I need a solution for the problem iam facing in building my site. Ihave groups and briefcase section in my site. I allow users to upload files and pictures.
    When they upload pictures i need to create thumbnail for them on the fly.
    Is there any taglibs or java source to do this from JSP or servlets.
    It would be very greatful if i can get an early answer.
    Please let me know if there is any other forum where i can get better answer, if not here?
    thnx.

    Here is how you can create dynamic images:
    http://developer.java.sun.com/developer/JDCTechTips/2001/tt0821.html#tip2
    However, if you want to create gifs/jpegs and save them to the disk it depends from where you want to create the images. It is different if you are creating from another image or just drawing one from scratch etc.. But in the end you will probably need to use one of the imageencoder classes and write the result to the disk with the file io classes.

  • How to call a method in the servlet from an applet

    I want to get the data for the applet from the servlet.
    How to call a method that exits in the servlet from the applet? I want to use http protocol to do this.
    Any suggestions? Please help.
    thanks

    Now that Web Services is around, I'd look at possibly implement a Web Service call in your applet, which can then be given back any object(s) on return. Set up your server side to handle Web Service calls. In this way, you can break the applet out into an application should you want to (with very little work) and it will still function the same

  • How to call servlet from jsp

    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.

  • Very urgent: call servlet from JSP

    Hello,
    I'm facing a problem in invoking a servlet from a JSP having the JSF components.
    The application has a text field to implement ajax for search functionality in the database .I have written a servlet to make the database connection and fire the querry.
    Ajax implementation in a js file is called on every keyup event in the jsp file,and
    a call is given to the servlet from the ajax methode.
    The function in the js file is as follows:-
    function getPersonByFirstNameXML( firstName ) {
        if (!firstName) {
            clearPersonByFirstNameXML();
        } else {   
            var url = BASE_URL + "/servlet/get_PersonsXML";
            alert(url);
            return new AJAXRequest("post", url, "firstName=" + encode(firstName), processGetPersonByFirstNameXML);
    }Im getting the myAJAX.status value as 500.
    I think I'm not able to access the servlet properly.
    what changes do i need to make in the we.xml file ?
    and what should be the url to be passed.
    Please provide me a sloution to the above problem as it is very urgent else if anybody is aware of a readymade JSF componet with search functionality freely available please let me know.
    PS:
    The 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
    is not available as stated in some of the suggestions by Author: mayagiri
    Thanks for any help.
    Abhi

    the status 500 generally means either HTTP server internal error or that execution of CGI script or servlet aborted with error.
    It can be reasonably supposed that the request reaches the servlet, ie. that "url" value points to some existing servlet, otherwise most probably the status value would be 404.
    To test that the servlet is working i'd try to access it using some simple html page with form like this (with {BASE_URL} replaced by real value):
    <form method=post action={BASE_URL}/servlet/get_PersonsXML>
    <input type=text name=firstName>
    <input type=Submit>
    </form>

  • Import a servlet from JSP without the use of a .JAR

    Migrating web app from NT / iPlanet 4.1 to Solaris / iPlanet 4.1.
    I've created a Web app in which JSPs utilize Servlets stored in a JAR file. I am now moving the app to a server that I do not control. I wish to configure the app in such a way that I will be able to modify the servlets and not have to restart the Web server to see the changes. I assume the only way to do this is to remove them from the JAR file.
    I'm familiar with how to package servlets in JAR files and use them in JSPs, but can't figure out how to import (my own) servlets from outside the JAR file. Is there any way to do this without specifying the servlet in the CLASSPATH?
    ...sorry if it's a stupid question, I'm not a Java programmer. Thanks in advance. Please let me know if I have not given enough detail.

    I've created a Web app in which JSPs utilize Servlets
    stored in a JAR file. I am now moving the app to a
    server that I do not control. I wish to configure the
    app in such a way that I will be able to modify the
    servlets and not have to restart the Web server to see
    the changes. I assume the only way to do this is to
    remove them from the JAR file.Bad assumption! This will have no impact on reloading the servlets!
    What you are asking for is called 'hot deployment'. Not all servers do that.
    Tomcat 4 does for instance, but you have to configure it for your specific webapp to be able to use it.
    Hot deployment just reloads all the classes in its classpath, it doesn't matter if they're in jars or just .class

  • Referring to Servlet from JSP

              Hi, I created a new web project in my workshop application and also created the
              directory structure: WEB-INF/src/mypackage/ to store all the java classes related
              to servlets and beans of my web project. I have a jsp page with few form fields
              whose submit action should invoke a servlet stored in /src/mypackage. How do I
              refer to the servlet in the JSP page that gets invoked on submit action?? [ form
              tag removed <!--- form action="???/MyServlet" method="POST"> ]. I am not sure
              where all the java class files are stored when I build the application using workshop.
              Another question I have is whether the build application will automatically include
              all the required servlets and taglibs in the web.xml file or this has to be done
              explicitly using Weblogic Builder?
              Thanks...
              

    How are you trying to create the link to the servlet? Are you using any
    tags?
    Subbu
    Christian Schlaefcke wrote:
    Hi Folks,
    I need set a servlet that produces an image output as source for an "img" tag in a jsp. I found several examples how this should be done with a simple webapp and these examples work right away in a simple tomcat environment.
    But BEA Portals are not comparable with simple webapps in combination with tomcat. The URLs for example are rendered in a special way, for example:
    http://localhost:7001/MyWebApp/My.portal?_nfpb=true&portlet_27_1_actionOverride=/portlets/Level1/aPortal/portalPage&portlet_27_1do_action=null
    My Problem:
    When I try to refer to my servlet like this
    img src="/servlet/ImageRenderServlet"
    The image is not rendered because the URL is not rendered. Even when I leave away the leading "/" of the servlet it becomes:
    http://localhost:7001/MyWebApp/servlet/ImageRenderServlet
    So whats the trick when referencing servlets from a jsp that belongs to a BEA Portlet?
    Thanks for any Help!
    Regards,
    Chris

  • Cannot invoke servlet from JSP

    I am trying to invoke a servlet from my JSP file. At present I am getting the error:
    500 Internal Server Error
    java.lang.IllegalArgumentException: Resource /servlet/CreateSPSS not found
         at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.EvermindPageContext.forward
    I understand that my JSP cannot find my servlet but I cannot identify what the correct path or amendment is.
    My JSP file is located in:
    default-web-app/examples/jsp/com.xml2spss.jsp
    In the JSP my forward parameter is :
    <jsp:forward page="/servlet/CreateSPSS" />
    and my servlet (.java & .class) is located in
    default-web-app/WEB-INF/classes/com/pmstation/spss/site/servlet.CreateSPSS.java
    I have added the following line to Web.XML:
    <servlet-mapping>
    <servlet-name>CreateSPSS</servlet-name>
    <url-pattern>/servlet/CreateSPSS</url-pattern>
    </servlet-mapping>
    Where am I going wrong??
    Thankyou for any help at all on this one.

    Shaun,
    Nice to know that you find a way that works. However, what Zsolt suggests should work; otherwise, it is a bug. That is, put the servlet definition and servlet mapping in your web.xml and then you should be able to access http://host:port/myWebContext/servlet/CreateSPSS?myParmName=myParm without seeing a response like "No resource found". Please make sure that your servlet definition come before the corresponding servlet mapping.

  • WL10 generated servlets from jsp pages

    hi!
    I'm looking for .java servlet files automatically generated from JSP (Weblogic 10). Do anybony know where can I find this files?
    Thanks in advace,
    Bartek

    Well, Servlet and JSP both are server side technologies and both can be used in web applications. You can write web pages using both servlet and JSP. In fact, your JSP pages are converted to Servlet by container while serving requests. However, writing a JSP page is relatively easier and requires minimal Java knowledge.
    When you will develop real world java based web applications you will find that you are writing more JSP pages than servlet.
    In a typical MVC (Model View Controller) architecture a single servlet is used as controller and JSP pages are used to generate web content.
    Thanks,
    Mrityunjoy

Maybe you are looking for

  • Custom Interface using Entity Objects

    Right now, we can only define cutom interfaces using the Generic Loader. I was wondering if this functionality is going to be extended so that users can define custom interfaces using EOs instead of lct files.

  • Upgraded to Mavericks, no longer get software updates on my applications

    I just upgraded from Mountain Lion to Mavericks last night, and now I can no longer download updates on my applications for my iMac. Before upgrading, whenever I got a notification saying that there was an update available, I would simply click on th

  • HP Proliant ML350G4 server - problem with array

    Hi, I have HP Proliant ML350 G4 server. The problem is that I can not configure the array for SCSI hard drives. When I run the Array Configuration Utility from the SmartStart CD, I get the message: "ACU did not detect any supported controllers in you

  • Connecting Sound Sticks to IMAC

    Just received Harmon Kardon Soundsticks III for Christmas,however, cannot get them to work on IMAC. What is really concerning is that Apple recommends them for use with IMAC. Is there a patch or driver available. Please help. Thanks!

  • Gos attachment knowlenge provider:  transfer error ?

    hi friends ı wrote this code but ı take this error 'Knowlenge provider : transfer error'. please help me ? thanks. DATA: o_document_set TYPE REF TO cl_bds_document_set,   wa_signature LIKE bapisignat,   i_signature LIKE bapisignat OCCURS 1,   wa_file