Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to call a method from servlet from JSP

Posted on 2006-11-12
9
Medium Priority
?
299 Views
Last Modified: 2010-08-05
Hi All,

This will be my first every JSP page.

All i have right now is this:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

The JSP page should get a QueryString parameter called message and send it to my servlet message.
http://myJavaWeb/sendMessage.jps?message=HelloWorld

How would a JSP page look like that does this.

The package of my servlet is
package Diversity.Java.Web.Servlet.PersistentHTTPconnection;

THe class defenition of the servlet is:
public class PersistentHTTPconnectiontHandler extends HttpServlet


0
Comment
Question by:DaFou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17924908
You can define in your web.xml the servlet mapping as the following:

 <servlet>
        <servlet-name>PersistentHTTPconnectiontHandler</servlet-name>
        <display-name>PersistentHTTPconnectiontHandler</display-name>
        <servlet-class>Diversity.Java.Web.Servlet.PersistentHTTPconnection.PersistentHTTPconnectiontHandler</servlet-class>
  </servlet>
<servlet-mapping>
        <servlet-name>PersistentHTTPconnectiontHandler</servlet-name>
        <url-pattern>/sendMessage.jps</url-pattern>
  </servlet-mapping>

This way you can call your servlet class when the url pattern matches the "/sendMessage.jps".
0
 
LVL 2

Author Comment

by:DaFou
ID: 17924989
but i want to call the servlet from my JSP and not have the webserver route in incomming request and response object to the servlet.

The method I want to call is:
public static void sendMessageToAlll(String message)

so how from the JSP do i call that method which is in a servlet
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 2000 total points
ID: 17925043
Can you call using a scriptlet?

for example,
<%
String message = request.getParameter("message");
PersistentHTTPconnectiontHandler.sendMessageToAlll(message);
%>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:DaFou
ID: 17925089
when compiling sendMessage.jsp containing this code:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%
String message = request.getParameter("message");
Diversity.Java.Web.Servlet.PersistentHTTPconnectiontHandler.sendMessageToAlll(message);
%>

I get the following error:
C:\Documents and Settings\root\PersitentHTTP\build\generated\src\org\apache\jsp\sendMessage_jsp.java:46: package Diversity.Java.Web.Servlet does not exist

The packagage containing the servlet is located in the source package folder of the current project in netbeans 5.0. The sendMessage.jsp is located in the Web Pages folder of the current project in netbeans 5.0
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17925123
Please check your classpath in "Library Manager".
0
 
LVL 2

Author Comment

by:DaFou
ID: 17925134
What should the class path look like?
0
 
LVL 2

Author Comment

by:DaFou
ID: 17925136
The werid thing is when I begin typing Diversity in my jsp page. It finds it in the dropdown and I can navigate all the way to persistantHTTPhandler.
But once there It does NOT find the public static sendMessageToAll
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17927637
make sure you have imported " PersistentHTTPconnectiontHandler"  and make sure Diversity.Java.Web.Servlet.PersistentHTTPconnectiontHandler is the right path in your jsp.
0
 
LVL 2

Author Comment

by:DaFou
ID: 17928351
I now have this but it still is not compiling.

<%@ page import="Diversity.Java.Web.Servlet.PersistentHTTPconnection"   %>
<%
String message = request.getParameter("message");
Diversity.Java.Web.Servlet.PersistentHTTPconnection.PersistentHTTPconnectiontHandler.sendMessageToAlll(message);
%>

compile:

Compiling 1 source file to C:\Documents and Settings\root\PersitentHTTP\build\generated\classes

C:\Documents and Settings\root\PersitentHTTP\build\generated\src\org\apache\jsp\sendMessage_jsp.java:6: package Diversity.Java.Web.Servlet does not exist

import Diversity.Java.Web.Servlet.PersistentHTTPconnection;

1 error

C:\Documents and Settings\root\PersitentHTTP\nbproject\build-impl.xml:361: The following error occurred while executing this line:

C:\Documents and Settings\root\PersitentHTTP\nbproject\build-impl.xml:353: The following error occurred while executing this line:

C:\Documents and Settings\root\PersitentHTTP\nbproject\build-impl.xml:141: Compile failed; see the compiler error output for details.

BUILD FAILED (total time: 5 seconds)


While every thing excists just fine
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As much as Microsoft wants to kill off PST file support, just as they tried to do with public folders, there are still times when it is useful or downright necessary to export Exchange mailboxes to PST files. Thankfully, it is still possible to e…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question