Wug
Wug

Reputation: 13196

How do I properly launch my introductory web application using maven's tomcat plugin?

I'm trying to write a simple JSP web application using maven for build management. My directory structure currently looks like this (but I've tried numerous other configurations, none of which have worked):

main
 `-- resources
 |-- webapp
 |    |-- WEB-INF
 |    |    `--web.xml
 |    |-- doLogin.jsp
 |    `-- index.jsp
 `-- java
      `-- com
           `-- wug
                `-- authen2cator
                     `-- LoginReq.java

index.jsp contains a simple form with datapoints username, password, and twofactor pointing to doLogin.jsp (this page seems to work fine).

doLogin.jsp references a bean, and pushes to it:

<jsp:useBean id="user" class="com.wug.authen2cator.LoginReq" scope="session" />
<jsp:setProperty name="user" property="*"/> 

LoginReq.java contains the following skeleton class:

package com.wug.authen2cator;

class LoginReq
{
    String username;
    String password;
    String twofactor;

    public LoginReq() {}

    public void setUsername(String n) { username = n; }
    public void setPassword(String n) { password = n; }
    public void setTwofactor(String n) { twofactor = n; }

    public String getUsername() { return username; }
    public String getPassword() { return password; }
    public String getTwofactor() { return twofactor; }
}

I'm trying to launch it with mvn tomcat:run after building. index.jsp works as expected, but doLogin.jsp throws a 500 error, and gives a stack trace starting with the following:

org.apache.jasper.JasperException: /doLogin.jsp(1,1) The value for the useBean class attribute com.wug.authen2cator.LoginReq is invalid.
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
    at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1229)
    at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)

I suspect that the problem lies with the tomcat environment, but this is the first time I've ever tried to use maven and I find its documentation to be somewhat lacking (the directory structures for different types of projects in particular are arbitrary and poorly documented for many project types)

I've tried taking LoginReq out of its package, and I've tried moving it around to various locations. It seems to compile if I put it in .../main/java (which did not exist when I generated the project, I had to create it) but not if I put it in .../main/webapp/WEB-INF, where most of the documentation I've read suggests it should be placed.

My suspicion is that tomcat isn't able to find LoginReq.class, and no combination of maven commands I've found seems to be actually starting tomcat using the correct WAR file that the build process is generating. I've run out of sensible ideas, and the documentation isn't helping. Can someone point me in the right direction?

Upvotes: 0

Views: 90

Answers (1)

cruftex
cruftex

Reputation: 5723

The LoginReq class must be declared public.

Upvotes: 1

Related Questions