Using the Parameter twice in a jsp page

I need to use a parameter twice I am really new to this and I know very little
about java I need to use it where I put HERE can anyone help me!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<jsp:useBean id="dbset"  class="Beans.dbset" />
<html>
<body>
<%String  res = request.getParameter("image_id");
String sql = "SELECT DISTINCT episode_id, episode_date, link FROM episode_char_Query where character_id = " + res ;
dbset.setQuery(sql);%>
<table>
<%
Vector outvec = new Vector();
   Vector invec = new Vector();
outvec = dbset.getResults();
invec = (Vector)outvec.elementAt(1);
for(int i=0; i<outvec.size(); i++)
%>
  <tr>
<%
for(int j=0; j<invec.size(); j++)
    if(i!=0 && j==0)
%>     <td align="center">
       <a href="episode.jsp?episode_id=<%=((Vector)outvec.elementAt(i)).elementAt(0).toString() %>&character_id ="HERE/>Click here to show scenes</a>
       </td>
<%    }
    if(i!=0 && j==2)
%>     <td align="center">
       <a href='C:\eastenders\<%=((Vector)outvec.elementAt(i)).elementAt(2).toString() %>'/>Click here to play episode</a>
       </td>
<%    }
    else
%>       <td align="center"> 
         <%= ((Vector)outvec.elementAt(i)).elementAt(j).toString() %>
         </td>
<%      }
%>
  </tr>
<%
%>
</table>
</body>
</html>

um.
yuck.
I would suggest you use some JSTL.
Mixing html and scriptlet code like this is a recipe for disaster:
And whats with all this if j==1, j==2 crap?
Seeing as you only have three items being returned, it would be much simpler just to have one loop, and access vector elements 0,1,2 directly rather than having a double loop.
At LEAST pull some of the stuff into temporary variables.
<c:forEach var="episode" items="${outvec}" varStatus="status">
  <c:choose>
    // first line is headings?
     <c:when  test="${status.first}">
        <td align="center">${episode[0]}</td>
        <td align="center">${episode[1]}</td>
        <td align="center">${episode[2]}</td>      
     </c:when>
        // all other lines print the data
     <c:otherwise>
  <tr>
    <td align="center">
       <a href="episode.jsp?episode_id=${episode[0]}&character_id=${param.image_id}">Show scene</a>
    </td>
    <td align="center">${episode[1]}</td>
    <td align="center"> <a href='C:\eastenders\${episode[2]}'> play episode </a></td>
  </tr>
  </c:otherwise>
</c:forEach>You see how much clearer it is without the nested looping and complicated if syntax?
Do yourself a favour - take a step back get JSTL and rewrite it from scratch.
You will be thanking yourself later.
Cheers,
evnafets

Similar Messages

  • How to retrieve the parameter names from a JSP page ? Urgent Please

    Hello,
    Can anybody tell me how to retrieve the parameter names from the JSP
    page. (without using getParameterNames() method.)
    The problem with the getParameterNames() method is I get the Jumbled output.
    I need it very badly
    With regards
    Ananth R
    email:[email protected]
    [email protected]

    Dear duffymo,
    My primary intention is to convert the JSP form information into a XML file.
    If I do not get the Parameter names in the correct order how can I maintain
    tag order in XML file.
    For ex: (JSP PAGE VIEW)
    Name--
    FirstName
    MiddleName
    LastName
    Address--
    Street1
    Street2
    City
    Country
    &so on
    (XML File to be generated)
    <Name>
    <FirstName>Value</FirstName>
    </Name>
    <Address>
    <street1>value</street1>
    </Address>
    & so on
    If I use getParameterNames() to get all the parameter names(Which form the tag names in the XML file ) the Enumeration object it returns will not be in the same order as the text fields in JSP.From this I can not construct a meaningful XML file.
    order means: Order of entry on the page, from top to bottom
    That's it
    Waiting for your responses

  • I want to use the method getRemotePort() in a jsp page.....................

    I have tried using it like this:
    <%@ page import="java.net.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import = "javax.servlet.*"%>
    <%
    out.println("<br>Remote Port : " +
    request.getRemotePort());
    %>
    I get the following error:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 4 in the jsp file: /test/cookie.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    C:\Tomcat\work\Standalone\localhost\_\test\cookie_jsp.java:51: cannot resolve symbol
    symbol : method getRemotePort ()
    location: interface javax.servlet.http.HttpServletRequest
    request.getRemotePort());
    ^
    1 error
    I think i need to import some page but am not sure which one. Can someone help on this please?

    well im using tomcat 4.1. Is there another way of getting the same information on the latest servlets? I mean instead of using getRemotePort() are there any other methods used in the latest servletes to get the same information?

  • UIX/JSP - How to use the UIX Controller with UIX/JSP

    After reading the UIX Developers Guide I am under the impression that I could use the UIX Controller with UIX/JSP pages. Is this correct and are there any available examples?
    Bill G...

    It's correct, but I'm afraid we don't have much (read as "any")
    documentation on how to do that - besides reading through the
    gobs of Javadoc and guessing how to put it together.
    Half of the problem is solved by registering JspPageDescriptions
    on a PageBroker (e.g., UIXPageBroker) to tell the UIX Controller
    to use a JSP to render a particular page, instead of a UIX XML
    document.
    The other half is getting the JSP to send requests back to
    the UIX Controller. Depending on how you've chosen to name
    your pages, create either a DefaultPageEncoder or ExtensionPageEncoder
    inside your JSP, and use that to create destination URLs.

  • How to get the view tree from a jsp page

    Hi,
    I would like to get the view tree of a jsp page. The idea is to dynamically include the content of one or more jsf pages into a UIPanel during a "value changed" event.
    So, i could get from an arbitrary page like ...
    <%@ taglib uri="http://java.sun.com/jsf/core"   prefix="f" %>
    <%@ taglib uri="http://java.sun.com/jsf/html"   prefix="h" %>
    <h:panelGrid columns="3" width="100%" rowClasses="gridTop">
        <h:outputText value="#{someBean.someValue}"/>
    </h:panelGrid>... the corresponding List of components...
    Any idea?

    Thanks for your answer Jayashri,
    The view tree can be retrieved by this way during the page is parsed, for example with scriptlets <%%>, or once the page has been parsed (the view has been builded and attached to the FacesContext).
    My problem is to get the view tree of a page from another Context.
    The idea is to build a dynamic layout of some pages that represents "views". I can imagine this like the concept of perspectives and views of Eclipse IDE.
    Because of the difficulty to build it with pure JSP (cannot use dynamic ID nor JSTL ForEach), I try to build it into my backing bean and to bind it with a <h:panelGrid/>. By this way, I'm not able to use the <jsp:include/> tag as I usually did to include some content into the view tree.
    Sorry for my english ;)
    - Renaud.

  • I am trying to create mobile pages using the steps file new new document page from sample mobile starters jquery mobile (cdn).  When "page from sample" is selected, the subsequent options are not available.  This seems like a silly question, but how do I

    I am trying to create mobile pages using the steps file>new>new document>page from sample>mobile starters>jquery mobile (cdn).  When "page from sample" is selected, the subsequent options are not available.  This seems like a silly question, but how do I acquire these options?

    You can get the latest jQuery Mobile Themes directly from jQuery Mobile's web site.
    https://demos.jquerymobile.com/1.1.0/docs/api/themes.html
    Or roll your own with ThemeRoller
    http://themeroller.jquerymobile.com/
    Nancy O.

  • The best  way of carrying the search string across different jsp pages?

    I heard about transfer object. What about carrying object with session for different pages.
    Please suggest me the best approach to
    carry the search string across different jsp pages?
    thanks
    vijendra

    I doubt its possible even with a fancy HTML widget, although the last iBA update now allows links to other books.

  • Why we need to use the RMI if you have JSPs? or vice versa

    Hi friends,
    Can anyone please explain me whats the difference between RMI and JSP?
    All I know is how to code and implement them both but can't figure out which one has more advantage than the other.
    Actually this was the Interview question asked to me once,
    The question was "Why we need to use the RMI if you have JSPs? or vice versa"
    Please let me know if you have any answers for this.
    Thank you.

    harsh884 wrote:
    Well I may not have very deep knowledge about them both but from the little bit of coding practice and implementation I know that too, that they are different technology and the implementation is also different. But didnt know what to answer for this question to interviewer.My answer would have been along the lines of using the right tool for the requirements. Use RMI when you want to work with remote objects "directly", but don't want to hassle with handling all the networking manually or restrict yourself to the HTTP protocol and an inappropriate use of the view layer in model 2 applications.
    Thanks anyways for the reply.You're welcome. How did the rest of the interview go?
    ~

  • Displaying Same ResultSet Twice In A JSP Page

    I have a table that lists team names in my database. I'm trying to create a page with 2 dropdown boxes where each lists all the teams in the league (in other words, the data read in from the table). I got the first dropdown box to populate w/ this info. My question is about the 2nd dropdown box:
    Since I already have the ResultSet from the 1st dropdown, I would think it would be a waste to make another DB-read to fill in the 2nd dropdown. However, when I tried to call ResultSet.first() it gave me the error that it was TYPE_FORWARD_ONLY. I checked the documentation for Connection and it looks like there are some overloaded methods for createStatement. However, the API documentation (see below) is pretty confusing. I'm not sure what "resultSetConcurrency" or "resultSetHoldability" I need if I just want to read the same data twice. Can someone point me in the right direction?
    Statement createStatement(int resultSetType, int resultSetConcurrency)
    Creates a Statement object that will generate ResultSet objects with the given type and concurrency.
    Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
    Creates a Statement object that will generate ResultSet objects with the given type, concurrency, and holdability.

    I am also having a very similar problem.
    I am having a table having 20 fileds.some of them r to be displayed in one table
    others in some other table.
    for this i am using a bean which returns a resultset which is then used in jsp page
    for display.But i have to call the javabean method twice which fires the query & returns the resultset.
    I cannot store so many fileds with so many rows of values in list of objects also i do not want to
    fire query twice.
    rs.movefirst() does not work, so what should i do.

  • How to use an BPM Instance Variable in JSP page

    Hi All,
    I am using the JSP Presentation, but i don't know how to use an Instance variable in JSP page, that instance already declared in the process. And Can u explain the syntax that to include the JS file into jsp page
    Regards
    Vasu.
    Edited by bpmvasu at 04/03/2007 10:43 PM

    Hi Mariano,
    I'm using JSP presentation too. In "Interactive Component Call" active i'm using "Use JSP presentation", but i only can define one instance variable, i need to add more instance variables. In "Advanced" option of this task, i have the argument mapping .. but i don't understand how to use it.
    I have a instance variable called "genders" of the type String[Int] (Associative Array) and i'm mapping this instance variable in "Arguments Show In" option of the advanced option of JSP presentation. In JSP presentation i have the code:
    <select <f:fieldName att="person.gender"/>>
                   <c:forEach var="gender" begin="0" items="${genders}" varStatus="status">
                        <c:choose>
                             <c:when test="${person.gender == gender}">
                                  <option value="<c:out value="${gender}"/>" selected="true"><c:out value="${gender}"/></option>
                             </c:when>
                             <c:otherwise>
                                  <option value="<c:out value="${gender}"/>"><c:out value="${gender}"/></option>
                             </c:otherwise>
                        </c:choose>
                   </c:forEach>
              </select>And in my screenflow i have the code:
    genders[0] = "Male"
    genders[1] = "Female"But when i run my application, i have the error: "The task could not be successfully executed. Reason: 'java.lang.ClassCastException: java.lang.Integer'."
    What's the problem?

  • How to use a session, created in a jsp page, in a php page

    Hello, forgive me for the newbie question.
    Here is my problem:
    I want to have a jsp page create a session, set some session variables and then redirect to a php page which will access those same session variables.
    I have the redirection worked out, but I can't seem to find out how to use the jsp session in my php script.
    Is this possible at all, and if so, how does it work?

    Note that javascript runs on the client side, and JSP runs on the server. JSP and the session objects are NOT available to javascript in reaction to the user.
    If this function is called only when the page is first created, not when the user interacts with the page, or if you want that value to be constant with respect to the javascript, then you can do this:
    <%
      String someValue = (String)session.getAttribute("theAttributeName");
    %>
    <script type="text/javascript">
         Calendar.setup({inputField:"f_date_dfFirstPmtDate",
                                              button:"f_trigger_dfFirstPmtDate",
                                             singleClick:true,
                                              ifFormat:<%=someVale%>});
    </script>

  • I want to use the custom request header in JSP How can I use that

    Hi Guys,
    I have following scenerio...
    1: There is one third party tool which is calling my.jsp page from the specified directory.
    2: Before calling the JSP that third party tool is adding some data like <user name> and <password > in the header of that JSP.
    Problem: I am not getting thos custom added header in side the JSP.
    Header information is given below:
    http://localhost:8100/wvsat/brand/ncr/auto.jsp
    GET /<APPLICATION_NAME>/ <JSP_PAGE_NAME>.jsp HTTP/1.1
    Host: localhost:8100
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Cookie: AreCookiesEnabled=195; JSESSIONID=2a30e33e48384dd13222
    MyUsername: demo*
    MyPassword : demo*
    HTTP/1.x 200 OK
    Date: Wed, 24 Sep 2008 19:42:22 GMT
    Content-Type: text/html; charset=UTF-8;application/x-www-form-urlencoded
    Connection: close
    Server: JRun Web Server
    Now within the JSp page i want the value of MyUserName and MyPassword
    For gettting these value i am using the request.getHeader(MyUserName);But it is returning null.
    Note:+*
    1: I want to forward this value to another servlet which is based on Struts framework_.
    2: For adding the value in the header i am using Http Live header Addons of FireFox_
    Could anyone help me in the same!!!
    Thanks in Advance

    Sorry, perhaps I was not explicit enough.
    Your code snippet: request.getHeader(MyUserName);
    It was missing quotes to make it a String value.
    If that is what you have, then it is using the VARIABLE MyUserName, and not the actual value "MyUserName"

  • How to integrate the following program in a JSP page

    I have this JavaMail program that sends emails. It runs from the command prompt. But I want to use it in a jsp page to send emails. But I am very new to JSP and dont know how to do it. Can anyone help me with it??
    It will be very helpful if someone gives the JSP code to send emails.
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class msgmultisendsample {
    public static void main(String[] args) {
    if (args.length != 6) {
    System.out.println("usage: java msgmultisend <to> <from> <smtp> true|false <message body 1> <message body 2>");
    return;
    String to = args[0];
    String from = args[1];
    String host = args[2];
    String msgText1 = args[4];
    String msgText2 = args[5];
    boolean debug = Boolean.valueOf(args[3]).booleanValue();
    // create some properties and get the default Session
    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    Session session = Session.getInstance(props, null);
    session.setDebug(debug);
    try {
    // create a message
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject("Trial Message from Braps.com");
    msg.setSentDate(new Date());
    // create and fill the first message part
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText(msgText1);
    // create and fill the second message part
    MimeBodyPart mbp2 = new MimeBodyPart();
    // Use setText(text, charset), to show it off !
    mbp2.setText(msgText2, "us-ascii");
    // create the Multipart and its parts to it
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    // add the Multipart to the message
    msg.setContent(mp);
    // send the message
    Transport.send(msg);
    } catch (MessagingException mex) {
    mex.printStackTrace();
    Exception ex = null;
    if ((ex = mex.getNextException()) != null) {
    ex.printStackTrace();
    }

    1) Design a Struts JSP page with TO, FROM, HOST, TEXT1, TEXT2 (3 text boxes and 2 textarea) and two buttons for SEND & RESET.
    2) Create a ActionForm Class and generate getters & setters for the above form elements
    3) Create ActionClass & define the action forward
    4) Do action mapping in struts-config.xml file
    5) Run and see whether you can able to open JSP page
    5) Create one more action class. This is to send email when you hit SEND button. Here only you're going to put your current code you have now.
    6) Do one more action mapping in struts-config.xml file, this time the forward page may a confirmation page saying that "Mail has been sent to <the TO id>.
    7) You're done.

  • How can I Locate the correct filepath in a jsp page?

    In http://localhost:8080/myweb/a.jsp, I will call a java bean file which is locate in http://localhost:8080/myweb/WEB-INF/classes/haha/DBConnection.class. This java file requires to read an external file which locates in http://localhost:8080/myweb/WEB-INF/classes/haha/db.txt
    My question is how can I get the correct filepath in this environment?
    inputStream = new BufferedReader(new FileReader(????????));
    Only this will work
    inputStream = new BufferedReader(new FileReader("D:\Program Files\Apache Software Foundation\Tomcat 5.5\db.txt"));
    But no one will place the file here, and it is impossible to do this when upload to 3rd party hosting.
    Any suggestion? thx.

    Thx all, in a jsp page, calling this method is fine.
    ServletContext s = getServletContext();
    String a = s.getRealPath("/");
    In a Servlet file, below method is ready to use:
    String b = getServletConfig().getServletContext().getRealPath("/");
    My problem is, I have a jsp page, which initialize a java bean , this java file is responsible for Database Connection, which will read the external text file to get the login, password and database name. So I won't need to recompile this file every time when I place in different platform with different configuration. I only need to edit the text file is ok.
    But How can I get the absolute file path when that jsp page initialize that java bean file? Below is my error, any suggestions are thx.
    package sql;
    import java.sql.*;
    import java.util.ArrayList;
    import java.io.FileReader;
    import java.io.BufferedReader;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class DBConnection extends HttpServlet{
    public String sql = null;
    public Connection con = null;
    public Statement statement = null;
    public ResultSet rs = null;
    private BufferedReader inputStream = null;
    private static ArrayList<String> arr = new ArrayList<String>();
      public DBConnection(){
        String fs = System.getProperty("file.separator");
        ServletContext s = getServletContext();
        String realpath = s.getRealPath("/");
        String filepath = realpath + "WEB-INF"+fs+"Properties"+fs+"db.txt";
        try{
          inputStream = new BufferedReader(new FileReader(filepath));
          String l;
          while ((l = inputStream.readLine()) != null) {
            arr.add(l);
          Class.forName("com.mysql.jdbc.Driver");
          this.con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+arr.get(0)+"?user=" +arr.get(1)+ "&password="+arr.get(2)+"&useUnicode=true&characterEncoding=utf-8");
          this.statement = this.con.createStatement();
        }catch (Exception e){
          System.err.println(e.getMessage());
        }finally{
    }java.lang.NullPointerException
         javax.servlet.GenericServlet.getServletContext(GenericServlet.java:159)
         sql.DBConnection.<init>(DBConnection.java:20)
         html.ShowCategory.<init>(ShowCategory.java:17)
         org.apache.jsp.left_jsp._jspService(left_jsp.java:66)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

  • Extracting a value from the j_security_check servlet into a JSP page

    Hi Folks...
    I have a problem as follows:
    I log in into the web app, via my login.jsp page. Below is the code for the form that accepts the login information
    <form method="POST" action="j_security_check">  
    <table cellpadding="0" cellspacing="0" border="0">  
      <tr>  
        <td align="right">Username: </td>  
        <td><input type="text" name="j_username"></td>  
      </tr>  
      <tr>  
        <td align="right">Password: </td>  
        <td><input type="password" name="j_password"></td>  
      </tr>  
      <tr>  
        <td></td>  
        <td><input type="submit" value="Login"></td>  
      </tr>  
    </table>  
    </form>Login is sucessful and I am brought to the 'studentstub.jsp' page. I would like the user name to appear on the 'studentstub.jsp' page. I used the following code in the 'studentstub.jsp' page :
    <td><%= request.getParameter("j_username")%></td>  but all I am getting is a null. The 'j_security_check' servlet is not exactly part of my package, but the glassfish app server. Is there anything wrong in the way I am extracting the information from 'j_security_check' ? Hope someone can advise, thanks.

    Hi Folks..
    I managed to get a reply from another forum and the suggested solution works. I am going to share it with everyone here.
    I repalced this line of code:
    <td><%= request.getParameter("j_username")%></td>with this:
    <td><%= request.getRemoteUser()%></td>The 'getRemoteUser' method from HttpServletRequest returns the name of the authenticated user. I hope this information will be helpful to those caught in a simillar problem. Thanks.

Maybe you are looking for