Reputation: 869
I'm trying to convert a Java class to be displayed on a web page. Using the top answer here as a guideline. The Java does what it's supposed to if I print everything out with System.out
. When trying to forward to a jsp page, it loops (re-instantiates?), and doesn't stop (have to manually kill the process).
Connector.java
public class Connector extends HttpServlet {
private static URL url = https://my.server.com/WEB-INF/ws/service.php?wsdl");;
private static final String USERNAME = "JoeBoB";
private static final String PASSWORD = "1337pass";
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//login to my.server.com
try {
authToken = serverAPI.login(USERNAME, PASSWORD);
System.out.println("Logged into server with Token: " + authToken);
//this shows up in console over and over again, until manually killed
}
catch (Exception ex) {
ex.printStackTrace();
}
request.setAttribute("message","bacon");
request.getRequestDispatcher("/WEB-INF/draw.jsp").forward(request, response);
//line above appears to be the one that re-inits the class.
//commenting this out stops the looping
//but also prevents the data from showing on the webpage
serverAPI.logout(authToken);
WEB-INF/draw.jsp
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>This is my drawn page</title>
</head>
<body>
${message}
</body>
</html>
WEB-INF/web.xml
<web-app>
<display-name>Connector</display-name>
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>com.company.package.Connector</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I have a feeling it's somewhat simple (something I forgot to configure, or misconfigured), but for the life of me can't figure out what.
Upvotes: 0
Views: 212
Reputation: 4411
By mapping /* to your servlet you are overriding the default handler for JSP requests. You need to use a more specific pattern, using a file extension or subdirectory.
Upvotes: 2