/    Sign up×
Community /Pin to ProfileBookmark

Calling a method in a JSP page from a servlet

Can I know how do I call a method in a JSP page when the method itself is in a servlet?

I have a SQL query in the servlet and I would like to call it in the JSP page. Can someone tell me how is it done?

[CODE] private void getFullName(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);

String username = “test”;
String password = “test”;
String thinConn = “jdbc:oracle:thin:@172.20.134.87:1521:ORCL”;

Connection conn;
Statement stm;
ResultSet rs;

String baseQuery =”SELECT FIRST_NAME||’ ‘||LAST_NAME AS FULLNAME FROM STAFF”;

try {
conn = DriverManager.getConnection(thinConn,username,password);
stm = conn.createStatement();
rs = stm.executeQuery(baseQuery);

while (rs.next()) {
String fullName = rs.getString(“FULLNAME”);
}
conn.close();
} catch (SQLException e) {
}
}[/CODE]

This is the codes that I would like to call in the JSP page.

[CODE]function searchStaff()
{

//search by first name
var name=document.getElementById(‘staffname’).value;
//search by last name
var name2=document.getElementById(‘staffname2’).value;

var themebasedfoi=mapview.getThemeBasedFOI(“themebasedfoi1”);
var themebasedfoi2=mapview.getThemeBasedFOI(“themebasedfoi2”);
if(id==3){
if(themebasedfoi==null)
{
themebasedfoi = new MVThemeBasedFOI(‘themebasedfoi1′,’TEST.search3’);
themebasedfoi.setQueryParameters(name,name2);
themebasedfoi.setBringToTopOnMouseOver(true);
mapview.addThemeBasedFOI(themebasedfoi);
}
else
{
themebasedfoi.setQueryParameters(name,name2);
themebasedfoi.setBringToTopOnMouseOver(true);
themebasedfoi.refresh();
}
}

else if(id==4){
if(themebasedfoi2==null)
{
themebasedfoi2 = new MVThemeBasedFOI(‘themebasedfoi2′,’TEST.search4’);
themebasedfoi2.setQueryParameters(name, name2);
themebasedfoi2.setBringToTopOnMouseOver(true);
mapview.addThemeBasedFOI(themebasedfoi2);
}
else
{
themebasedfoi2.setQueryParameters(name, name2);
themebasedfoi2.setBringToTopOnMouseOver(true);
themebasedfoi2.refresh();
}
}
}[/CODE]

This is the function that I would like to place the query in which is the JSP page. Any help would be much appreciated.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @qwerty2412 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...