Trying to trigger a servlet from .jsp page on combo box change

I have a jsp page with two combo boxes ( single select ).
Here's a snippet from the jsp page containing the code for the two combo boxes:
<form name="frmCountry" id="frmCountry" method="POST">
     <select name="selCountry" id="selCountry">
          <jsp:include page="/country" />
     </select>
</form>
<form name="frmCity" id="frmCity" method="POST">
     <select name="selCity" id="selCity">
          <jsp:include page="/city" />
     </select>
</form>
"country" and "city" are both mapped to servlets in the web.xml file
The country servlet successfully connects to the database and retrieves all countries
and populates the country combo box.
However, the populating of the city combo box depends on what country
is selected in the country combo box;
Here is a snippet of my code from the City servlet:
ResultSet rs;
rs = statement.executeQuery("SELECT City.countryID, City.id, City.name " +
               "FROM City " +
               "WHERE City.countryID = ( Country id ) " +
               "ORDER BY City.name");
Where ( Country id ) has to be somehow retrieved from the Country combo box
on the jsp page. Country id is actually the "value" property of each <option> in the
Country combo box. i.e.:
<option value="5">Portugal</option>
If it's not possible to retrieve the value property from the option,
I could always just use the Country name
So to reiterate, I need the City servlet to be called into action
any time a different country is selected in the country combo box.
I'm a newbie to jsp & servlets, so any suggestions much appreciated.
Edited by: Irish_Fred on Jan 20, 2010 4:29 AM

Cheers, I came up with a solution using Ajax, where I didn't have to change
anything in my servlets and only had to make minor changes to my jsp page.
I didn't want to use any javascript in my web app, but I guess Ajax
has addressed the issue of cross platform independence.

Similar Messages

  • 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.

  • 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

  • How to run servlet from JSP page

    A simple JSP page,where I will put a button.And on clicking..it will invoke the servlet and the servlet will send the result to the jsp page...
    Please give the instructions with examples...
    Thanks in advance...

    hi,
    Create a jsp inside webapps/root
    <a href="./howtocode" > click to call servlet </a>and follow the steps
    http://forum.java.sun.com/thread.jspa?threadID=5202830

  • IllegalAccessError trying to instantiate public class from JSP page

    I have a public class called UrlHolderClient located in both
    WEB-INF/classes/UrlHolderClient.class and
    WEB-INF/lib/urlholder.jar.
    This client class is used as a wrapper class around a simple ejb which holds urls. I have a JSP which tries to create an instance of UrlHolderClient in jspInit(), but the call to the constructor throws a java.lang.IllegalAccessError. I have no idea what the problem is here. I import the classes using the page directive.
    Any suggestions?

    Is this tomcat you are deploying on or some other App Server?
    Also, you reference JspInit(), have you tried instanting in
    Scriplet Code <% UrlHolderClient urlHolderClient = new UrlHolderClient() %>
    Does that not work either?

  • Insert data into table from JSP page using Entity Beans(EJB 3.0)

    I want to insert data into a database table from JSP page using Entity Beans(EJB 3.0).
    1. I have a table 'FRIENDS', (in Oracle 10g database).
    2. It has two columns, 'NAME' and 'CITY'. Both have datatype strings(varchar2).
    3. Now from a JSP page, having two textfields, 'NAME' and 'CITY', I want to insert data into table 'FRIENDS'.
    4. In between JSP and database is a Entity Bean(EJB 3.0) and a stateless session bean.
    5. I am using JDev as editor.
    Please provide me code ASAP or link with similar example.
    Thank you.
    Anurag

    Hi,
    I am also trying that scenario. So u can
    Post the jsp form data to a Servlet which will act as a Controller.
    In the servlet invoke the business method.
    Similar kind of app is in www.roseindia.net
    Hope this would help u.
    Meanwhile if u get any optimal solution, pls post it.
    Thanks,
    Happy Java Coding.

  • 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.

  • Calling Beans from JSP page

    hi,
    I tried to my best to call java beans from JSP page but it generate error that "unable to load class....", please help me that in which directory jsp file and bean *.class file reside, currently my setting are as follows.
    Note: I am using tomcat server and my jsp and servlet files are running seccessfuly, there is any special change in classpath for java beans? if any please tell
    My jsp file is in tomcat-->webapps-->jsp--><my file>
    My bean (*.class) file-->webapps-->Root-->web-inf-->classes--><my file>
    Pleae help me for the above problem.
    Mubashar ([email protected])

    According to J2EE standards:
    The web appl directory structure should be:
    WebAppRootDirectory
    |
    |---html, jsp, images etc
    |
    |---WEB-INF---
    |---classes--
    |---lib
    |
    |
    1) Make sure WEB-INF is in capital letters
    2) Place all ur beans in classes dir or sub-directory in
    classes
    3) In Tomcat place WebAppRootDirectory in webapps
    directory
    [email protected]

  • 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 get the form reference in .js page from .jsp page

    hi
    i have written one form in jsp page omething like:-
    <html:form action="/shopping" onsubmit="return false;">
    can anybody tell me,how to get the form reference in .js page from .jsp page ,
    i have tried:-
    var formRef = document.forms[0];
    butits not working.
    Thanks.

    Its very simple......y cant u prefer google...Bad
    c this example...
    function submit()
    alert("textbox"+ document.forms[0].name.value);//to get textbox value in js
    document.forms[0].submit();//to submit jsp page using js
    <html:html>
    <html:form action="/shopping" onsubmit="submit()">
    <html:text property=name>
    learn to search in google..
    </html:form>
    </html:html>

  • 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,

  • Problems calling Java Servlets from HTML pages Online

    Hello
    I have created a Web site using Java Servlets, and have acquired some servlet enabled web-space however i am having some difficulty in calling the actual servlets from the HTML pages i was using the line of code as follows
    http://localhost:8080/servlet/....
    followed by the name eg.
    http://localhost:8080/servlet/Login
    however this doesn't seem to be working i have also tried using the exact address of the servlet but this didn't work either
    i.e ..servlet/Login.java
    I was wondering would anyone have any idea as in how the servlets should be called
    Thanks very much

    Once you write the Servlet code, you have to compile and put the classes in the server classpath. To refer these servlets from your pages, you have to configure them in the server configuration(typical a xml file). There you define how you are going to refer to the servlet(/servlet/Logon) and the correponding class.
    -Mak

  • Removing ADFBindingFilter from jsp page

    I have showReport()method in showReport bean (it is not registered in faces-config.xml as managed-bean) that I am calling from jsp page with JSP call showReport.showReport(). My showReport() method looks like this:
    FacesContext fc = FacesContext.getCurrentInstance();
    ValueBinding vb = fc.getApplication().createValueBinding("#{data.documentReportsPageDef}");
    DCBindingContainer dc = (DCBindingContainer) vb.getValue(fc);
    OperationBinding execute =
    dc.getOperationBinding("ExecuteWithParams");
    execute.execute();
    Headless_ documentReportsPageDef code:
    <pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
    version="10.1.3.36.73" id="documentReportsPageDef"
    Package="...view.pageDefs">
    <executables>
    <iterator id="DocumentReportsIterator" Binds="DocumentReports"
    RangeSize="-1" DataControl="AppModuleDataControl"/>
    </executables>
    <bindings>
    <action id="ExecuteWithParams" IterBinding="DocumentReportsIterator"
    InstanceName="AppModuleDataControl.DocumentReports"
    DataControl="AppModuleDataControl" RequiresUpdateModel="true"
    Action="95">
    <NamedData NDName="DocumentType" NDValue="@CDBR"
    NDType="java.lang.String"/>
    <NamedData NDName="RefNo" NDValue="12635"
    NDType="java.lang.String"/>
    <NamedData NDName="IsInstant"
    NDValue="1"
    NDType="java.lang.String"/>
    </action>
    <table IterBinding="DocumentReportsIterator" id="DocumentReports" >
    <AttrNames>
    <Item Value="Id"/>
    <Item Value=".."/>
    </AttrNames>
    </table>
    </bindings>
    </pageDefinition>
    It is registered in DataBindings.cpx
    Everything works fine until I remove:
    <filter-mapping>
    <filter-name>adfBindings</filter-name>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    from web.xml so ADFBindingBindingFilter would not be invoked for my jsp page. I have reason for this
    On execute.execute()line I get:
    Resolving collection source:DocumentReports for iterator binding:DocumentReportsIterator
    DCUtil, returning:oracle.adfinternal.view.faces.model.binding.FacesCtrlRangeBinding, for DocumentReports
    Looking for RSI with name :DocumentReports for iterator binding:DocumentReportsIterator
    DCBindingContainer.reportException :oracle.jbo.JboException
    oracle.jbo.JboException: JBO-29000: Unexpected exception caught: java.lang.NullPointerException, msg=null
    If I restore filter-mapping so adfBindings are used for *.jsp page I get:
    Resolving VO:DocumentReports for iterator binding:DocumentReportsIterator
    DCUtil, returning:oracle.adfinternal.view.faces.model.binding.FacesCtrlRangeBinding, for DocumentReports
    Column count: 13
    So everything works fine again.
    Question: Can I make this work without ADFBindingsFilter on jsp page? I am invoking everything programmatically and I don’t understand why I need to set this filter on jsp?
    With this strange implementation, I am trying to solve problem discussed in article:
    oracle.jbo.common.Lock locks the application
    If my idea is hopeless, please clarify me this :)

    Ok, this is quite clear answer. Thank You.
    One more thing:
    In oracle.jbo.common.Lock locks the application Steve M, has left the the question open by "I'll ask one of our developers to comment in this thread on ideas for implementing this long-running report.". Maybe You could close this one too?

  • 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

  • Send message from JSP page to Java message driven bean

    Hi all
    I'm using Jdev903.
    I need to send a message from JSP page (Web Application) to Java Message Driven Bean.
    * I created Message Driven Bean that named: MyMessageDrivenEJBBean
    * I have configed jms.xml:
    <topic-connection-factory name="ChatTopicConnectionFactory" location="jms/theTopicConnectionFactory"/>
    <topic name="ChatTopic" location="jms/theTopic"/>
    * In JSP page, my code is:
    final Context ctx = new InitialContext();
    // 1: Lookup ConnectionFactory via JNDI
    TopicConnectionFactory factory =(TopicConnectionFactory)ctx.lookup("jms/theTopicConnectionFactory");
    But trouble occurs is:
    javax.naming.NameNotFoundException: jms/theTopicConnectionFactory not found
    please help me!
    thank a lot.

    Welcome to the Sun forums.
    1. Please post your code using code tags, this formats it so that it is easier for people to read and understand it. Click on 'CODE' above the text area when posting.
    2. As far as possible, please post an SSCCE
    What have learnt about JSPs and servlets till now? Because reading the values submitted in a form is pretty much the base of all operations. I suggest you Google for [servlet tutorials|http://www.google.com/search?q=servlet+tutorial] and [JSP tutorials|http://www.google.com/search?q=jsp+tutorial] and go through them thoroughly. After you understand what is to be done and what options are available to you, if you still face problems, please feel free to post your queries here. But this isn't exactly a site for tutorials, especially since there are so many good ones already out there, that explain all this stuff in detail. There's no point in re-inventing the wheel.
    Hints: [ServletRequest#getParameter()|http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameter(java.lang.String)] and [RequestDispatcher#forward|http://java.sun.com/javaee/5/docs/api/javax/servlet/RequestDispatcher.html]

Maybe you are looking for

  • How do I change Itunes from one account to two in my home?

    how do I change Itunes from one account to two in my home?

  • Does anyone have this issue

    Why my iPod touch won't play movies when I connect it to car radio it use to work before

  • Stylesheets + J2sdk 1.4

    I have recently migrated my code from j2sdk 1.3.1_03 to j2sdk 1.4.1_02. I am using JavaHelp 1.1.3. All my html pages where previously successfully imcluding a style sheet for displaying the help. In 1.4.1_02 the style sheet is not being applied. I ha

  • Create Global Temporay Table

    I am converting some Informix ESQL/C programs to Oracle Pro*C. However the "Create Global Temporay Table" statemnt does not seem to be recognized by Pro*C precompiler. Does anyone know why? Thank You

  • ?? Create a link to a slide show

    How do I create a link to a slide show in iWeb. I realize that the picture page has one built in but what if I want to create a link on a separate page linking directly to the slide show? PLEASE SOMEONE HELP ME, Im going nuts trying to figure this ou