Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:07:52+00:00 2026-06-04T22:07:52+00:00

I have a JSP file inputs a string to a Java class, and should

  • 0

I have a JSP file inputs a string to a Java class, and should get an ArrayList returned from it. Do I need a public class (i.e. void main(String[] args) ) to be able to return to the calling JSP, or is public Scopus() enough to return the values?

Scopus.java (accepts in scopusID, returns scopusList)

package newpackage1;
import org.w3c.dom.Document;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.util.ArrayList;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

public class Scopus {

    String scopusID;
    URL url;
    ArrayList<String> scopusList = new ArrayList<String>();
    NodeList nodes;
    DocumentBuilder builder;
    Document doc;

    public void setScopusList(ArrayList scopusList) {
        this.scopusList = scopusList;
    }

    public ArrayList getScopusList() {
        return scopusList;
    }

    public void setScopusID(String url) {
        this.scopusID = url;
    }

    public String getScopusID() {
        return scopusID;
    }

    public Scopus(String scopusID) {

        String fTitle, fLink;

        try {
            URL url = new URL( "http://syndic8.scopus.com/getMessage?registrationId=" + scopusID );
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
    }

        try {
            builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            doc = builder.parse(url.openStream());
            nodes = doc.getElementsByTagName("item");
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (SAXException e) {
            throw new RuntimeException(e);
        }

        //Only output if at least one is found
        int counter = 0;
        if ( nodes.getLength() > 0 ) {
            //Place all results into an array list first
            for(int i=0;i<nodes.getLength();i++) {
                Element element = (Element)nodes.item(i);
                fTitle = getElementValue(element, "title");
                fLink = getElementValue(element, "link");

                scopusList.add("<a href=\"" + fLink + "\" target=\"_blank\">" + fTitle + "</a>");

                counter++;
            }
         }

    }

    public static void main(String[] args) {


    }

    private String getElementValue(Element parent,String label) {
        return getCharacterDataFromElement((Element)parent.getElementsByTagName(label).item(0));
    }
    private String getCharacterDataFromElement(Element e) {
        try {
            Node child = e.getFirstChild();
            if(child instanceof CharacterData) {
                CharacterData cd = (CharacterData) child;
                return cd.getData();
            } //if
        } //try
        catch(Exception ex) {

        }
        return " ";
    } //private String getCharacterDataFromElement
}

output.jsp (Calls the above class)

<%@page import="java.util.ArrayList,org.w3c.dom.Node,org.w3c.dom.NodeList" %>

<%
   String feedID = "HEDCIHLCIGDKPFHHJEEEHJDEIEGJIKJHKWFQWLHFJH";
%>

<jsp:useBean id="scopus" scope="page" class="newpackage1.Scopus">
    <jsp:setProperty name="scopus" property="scopusID" value="<%= feedID %>" />
</jsp:useBean>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <jsp:getProperty name="scopus" property="scopusList" />

        <%

        ArrayList sl = scopus.getScopusList();
//Will do output later
%>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:07:53+00:00Added an answer on June 4, 2026 at 10:07 pm

    The class you specify in class must not be abstract and must have a public, no-argument constructor which you don’t have.

    Update:: You don’t need main() method, a public Scopus() non-argument constructor will be fine. The JSP container will create an instance of this class using reflection using the zero-argument constructor. If you don’t create any constructor, Java compiler will add one to the compiled class. You only need to rename your original constructor with parameter to make it a method to do all those business logic things and call it somewhere after you have set scopusID property and before the getScopusList() method is called (when you try to access the scopusList property).

    As for the presentation of the list data, it is not a good idea to use:

    <jsp:getProperty name="scopus" property="scopusList" />
    
    <%
        ArrayList sl = scopus.getScopusList();
    //Will do output later
    %>
    

    You better use JSP EL and JSTL core taglib and do something like this:

    <c:forEach items="${scopus.scopusList}" var="item">
        ${item}<br/>
    </c:forEach>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have following in my struts.xml file <action name=ProductVerification class=com.frontend.ProductVerification> <result name=success>/jsp/product_verification.jsp</result> <result name=input>/jsp/product_verification.jsp</result>
I have jsp file: <%@ page language=java contentType=text/html; charset=UTF-8 pageEncoding=UTF-8%> <%@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core%>
I need to open a new window from a jsp file. In a JSP
I have a jsp file which contain javascript functions at top of file. These
I have a jsp file in the root of .war file. and then I
I have a .jsp file that receives a request and checks the request's parameters.
I'm getting an exception when i have my jsp file on the webserver, it
I have a index.jsp file that has two different types of forms <form action=searchpath
I have created a child.jsp file which has a button named Continue. I have
I have these in a jsp file. But these values are not updated in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.