3

I'm following a tutorial on Udemy that explains JSPs and Servlets: https://www.udemy.com/jsp-tutorial

The tutorial uses Eclipse + Tomcat server.

Since I'm an IntelliJ and Maven user I wanted to set up my environment using these two. So I created a Maven project from the following archetype: "org.apache.maven.archetypes:maven-archetype-webapp" and configured my POM as folllows:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>SomeGroupId</groupId>
  <artifactId>HelloWorldJavaServerPages</artifactId>
  <packaging>war</packaging>
  <version>1.0</version>
  <name>HelloWorldJavaServerPages Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>javax.servlet.jsp-api</artifactId>
      <version>2.3.1</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>HelloWorldJavaServerPages</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <url>http://localhost:8080/manager/text</url>
          <server>Tomcat85Localhost</server>
          <username>admin</username>
          <password>admin</password>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Set up my other properties as described here: Tomcat 8 Maven Plugin for Java 8

I am able to build my project and use the tomcat plugin to deploy to the tomcat server (or manually drag the war file in the webapps folder).

Problem is that when I have the following two files:

student-form.html

<html>
<head><title>Student Registration Form</title></head>
<body>
<form action="student-response.jsp">
    First name: <input type="text" name="firstName" />
    <br/>
    Last name: <input type="text" name="lastName" />
    <input type="submit" value="Submit" />
</form>
</body>
</html>

student-response.jsp

<html>
<head><title>Student Confirmation Title</title></head>
<body>
    The student is confirmed: <%= request.getParameter("firstName")%> ${param.lastName}
</body>
</html>

The request.getParameter method works, but the ${param.lastName} does not and it simply shows up as plain text in the browser: ${param.lastName}.

Using Eclipse (without Maven) it does work for both, so I'm wondering what I'm doing actually different/wrong here and why it is not working.

Thanks in advance for your help.

Dripbrew
  • 53
  • 5

1 Answers1

0

Once I found out that the references between the braces are called the "Expression Language", I decided to do another search on stackoverflow and found this: Expression Language in JSP not working

Changing the web.xml as described in the link above made it work.

Thank you all for reading my question, the answer was quite simple actually.

Dripbrew
  • 53
  • 5