3

I'm getting errors (on X lines) in a jsp file but it all seems to be right.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

    <form method="GET"
X           action="${pageContext.request.contextPath}/docreatetask">
        <table>
            <tr>
                <td>Task</td>
                <td><input name="task" type="text" /></td>
            </tr>
            <tr>
                <td>Description</td>
                <td><input name="description" type="textarea" /></td>
            </tr>
            <tr>
                <td>Deadline</td>
                <td><input name="description" type= /></td>
            </tr>
            <tr>
                <td></td>
X                   <td><input name="Create new task" type="submit" /></td>
            </tr>
        </table>
    </form>

</body>

**Error 1** javax.servlet.ServletException can not be resolved
**Error 2** javax.servlet.http can not be resolved

What could it be? Is it using ServletException or javax.servlet.http anywhere?

Joe
  • 7,749
  • 19
  • 60
  • 110
  • Is only this jsp showing error or if there are other they are also showing – Dhruv Pal Feb 14 '14 at 09:03
  • Project works fine but the editor is showing that errors – Joe Feb 14 '14 at 09:11
  • @Joe I am asking if this particular jsp is showing error or all are. – Dhruv Pal Feb 14 '14 at 09:20
  • if your project works fine it can be a small problem .Do one thing select all your jsp page copey all contents of jsp press del and paste again and save..But if all jsps showing problem then add servlet -api jar – Dhruv Pal Feb 14 '14 at 09:22
  • I tried that and it works for a while, but afterwards the same error came up again. Finally I added servlet-api.jar in classpath. Thanks for the advice! – Joe Feb 14 '14 at 09:54

1 Answers1

3

For your first error (java.servlet.http can not be resolved to a type), You need to put servlet-api.jar file in the `classpath:

To do this follow the steps:

  1. Right click on the project.
  2. Click on build path -> Configure build path
  3. In libraries tab -> click Add external jars
  4. Select servlet-api.jar file

For your second error:(javax.servlet.ServletException can not be resolved):

  1. Right Click on project
  2. Select Properties tab
  3. Select targeted runtime tab
  4. Check the server you are using
Bhushan
  • 6,151
  • 13
  • 58
  • 91
  • It worked fine. But I can't understand where I'am using such classes. It was only html in it. – Joe Feb 14 '14 at 09:30
  • 1
    @Joe by using `${pageContext.request.contextPath}` in your code, you are using `HttpServletRequest` object which requires `servlet-api.jar` file. Have a look at [this link](http://stackoverflow.com/a/5850406/1551233). – Bhushan Feb 14 '14 at 09:40
  • 1
    @Joe also there are some errors in your html code. You are defining `textarea` wrong way. And you have not specified `type` for `description` input. – Bhushan Feb 14 '14 at 09:42