• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

HTTP Status 500 - --Only a type can be imported

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index</title>
</head>
<body>
<form method="get" action="loggin">
<h3>Enter the Vehicle ID</h3> <input type="text" name="vehicleID" />
<br>
<br>
<input type="submit" value="Submit"/>

</form>
</body>
</html>

logginServlet.java

package org.nissan.abhi;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nissan.abhi.dto.Cars;
import org.nissan.service.logginservice;



public class logginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException
{

try
{
doPost(req,res);
}
catch(IOException e)
{

}

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


String vehicleID;

response.setContentType("text/html");

vehicleID= request.getParameter("vehicleID");
logginservice lgnsrv = new logginservice();
boolean result = lgnsrv.authenticate(vehicleID);



if(result)
{
Cars car2= lgnsrv.getCarDetails(vehicleID);
RequestDispatcher dispatcher = request.getRequestDispatcher("success.jsp");
dispatcher.forward(request, response);
return;
}
else
{
response.sendRedirect("index.jsp");
return;
}


}

}


logginservice.java

package org.nissan.service;

import java.util.HashMap;

import org.nissan.abhi.dto.Cars;

public class logginservice {

HashMap<String,String> cars = new HashMap<String,String>();

public logginservice()
{
cars.put("1234","Nissan");
cars.put("4567","Ford");
cars.put("8910","Dodge");
}


public boolean authenticate(String VehicleID){
if(VehicleID == null || VehicleID.trim()=="")
{
return false;
}
return true;
}

public Cars getCarDetails(String vehicleID)
{
Cars car1 = new Cars();
car1.setVehicleID(vehicleID);
car1.setCarName(cars.get(vehicleID));
return car1;

}
}


Success.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="org.nissan.abhi.dto.Cars" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Success</title>
</head>
<body>
<h5>Loggin Successful</h5>
<%
Cars car =(Cars) request.getAttribute("cars");

%>
Vehicle ID : <%=car.getVehicleID()%>
Car Type : <%=car.getCarName()%>
</body>
</html>

Cars.Java

package org.nissan.abhi.dto;

public class Cars {

private String vehicleID;
private String carName;

public String getVehicleID() {
return vehicleID;
}
public void setVehicleID(String vehicleID) {
this.vehicleID = vehicleID;
}
public String getCarName() {
return carName;
}
public void setCarName(String carName) {
this.carName = carName;
}

}

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Nissan1</display-name>
<servlet>
<servlet-name>logginServlet</servlet-name>
<servlet-class>org.nissan.abhi.logginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>logginServlet</servlet-name>
<url-pattern>/loggin</url-pattern>
</servlet-mapping>


<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>

I’m getting the Error:
HTTP Status 500 -
________________________________________
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 6 in the generated java file
Only a type can be imported. org.nissan.abhi.dto.Cars resolves to a package

An error occurred at line: 12 in the jsp file: /success.jsp
Cars cannot be resolved to a type
9: <body>
10: <h5>Loggin Successful</h5>
11: <%
12: Cars car =(Cars) request.getAttribute("cars");
13:
14: %>
15: Vehicle ID : <%=car.getVehicleID()%>


An error occurred at line: 12 in the jsp file: /success.jsp
Cars cannot be resolved to a type
9: <body>
10: <h5>Loggin Successful</h5>
11: <%
12: Cars car =(Cars) request.getAttribute("cars");
13:
14: %>
15: Vehicle ID : <%=car.getVehicleID()%>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Double check to make sure the org.nissan.abhi.dto.Cars file is present under WEB-INF/classes directory.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags when posting to forums, unformatted code are very difficult to read. First, if you are learning servlets/jsp, recommend you to start with good programming habits, i.e not to use any scriptlets in JSP, instead you should use JSTL.
 
Abhilash Ravishankar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Minawa,

Thanks for replying.The code worked fine.The org.nissan.abhi.dto.Cars is in Java Resources. I didn't understood the problem I'm experiencing.I feel there is some problem with the TomCat server.When ever I enter to debug mode and execute it and restart Eclipse, it stars working.Please help me to configure correctly the Tomcat Server with the eclipse or any changes need to be done in the settings.Thank you.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i believe request.setAttribute("cars", car2); is needed, so that you can get the object in your JSp when you call request.getAttribute method.
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Krishnegowda wrote:recommend you to start with good programming habits, i.e not to use any scriptlets in JSP, instead you should use JSTL.


Do not discount this advice -- it's very good advice. Java scriptlets in a JSP are outdated and discredited and a very poor practice.
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic