我在jsp/Eclipse IDE中遇到错误:“只有类型可以被导入”。

huangapple 未分类评论47阅读模式
英文:

I get the error "Only a type can be imported" in jsp/Eclipse IDE

问题

以下是您提供的内容的翻译:

我正试图在Eclipse IDE中的Dynamic WEB App项目中应用CRUD功能,使用tomcat v9.0。在提供输入后,我得到了以下错误信息:

类型:异常报告

消息:无法编译JSP类:

描述:服务器遇到了意外情况,阻止了它完成请求。

异常:
org.apache.jasper.JasperException:无法编译JSP类:

在生成的Java文件的第14行发生错误:[C:\Program Files\Apache Software Foundation\Tomcat 9.0\work\Catalina\localhost\Testing4\org\apache\jsp\Controller\insert_005fcontroller_jsp.java]
只能导入类型。crud.Insert_Values解析为包

在jsp文件的第20行发生错误:[/Controller/insert_controller.jsp]
无法解析Insert_Values为类型
17: String user_name = request.getParameter("user_name");
18:
19:
20: Insert_Values obj_Insert_Values = new Insert_Values();
21: obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
22:
23:

在jsp文件的第20行发生错误:[/Controller/insert_controller.jsp]
无法解析Insert_Values为类型
17: String user_name = request.getParameter("user_name");
18:
19:
20: Insert_Values obj_Insert_Values = new Insert_Values();
21: obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
22:
23:

这是我的Java类:

package crud;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import common.DB_Connection;

public class Insert_Values {
	
	public void insert_values(String sl_no, String user_name, String email, String mobile) {
		
		DB_Connection obj_DB_Connection = new DB_Connection();
		Connection connection = obj_DB_Connection.getConnection();
		
		PreparedStatement ps=null;
		
		String query = "insert into user(sl_no, user_name,email,mobile) values(?,?,?)";
		try {
			ps=connection.prepareStatement(query);
			
			ps.setString(1, sl_no);
			ps.setString(2, user_name);
			ps.setString(3, email);
			ps.setString(4, mobile);
			
			ps.executeUpdate();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}	

这是我的JSP文件之一:

<%@ page import="crud.Insert_Values"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
	String sl_no = request.getParameter("sl_no");
	String email = request.getParameter("email");
	String mobile = request.getParameter("mobile");
	String user_name = request.getParameter("user_name");

	
	Insert_Values obj_Insert_Values = new Insert_Values();
	obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
	
%>

完成

</body>
</html>

这是另一个JSP文件:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<h1>插入值</h1>

<form action = "Controller/insert_controller.jsp">

Sl No :<input type = "text" name = "sl_no"><br>
User Name :<input type = "text" name = "user_name"><br>
Mobile: <input type ="text" name = "mobile"><br>
Email: <input type = "text" name = "email"><br>

<input type = "submit" value = "插入">

</form>

</body>
</html>
英文:

I'm trying to apply CRUD function in a Dynamic WEB App project in Eclipse IDE with tomcat v9.0. After giving inputs I get the error -

Type: Exception Report

Message: Unable to compile class for JSP: 

Description: The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception:
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: [14] in the generated java file: [C:\Program Files\Apache Software Foundation\Tomcat 9.0\work\Catalina\localhost\Testing4\org\apache\jsp\Controller\insert_005fcontroller_jsp.java]
Only a type can be imported. crud.Insert_Values resolves to a package

An error occurred at line: [20] in the jsp file: [/Controller/insert_controller.jsp]
Insert_Values cannot be resolved to a type
17: 	String user_name = request.getParameter(&quot;user_name&quot;);
18: 
19: 	
20: 	Insert_Values obj_Insert_Values = new Insert_Values();
21: 	obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
22: 	
23: 	

An error occurred at line: [20] in the jsp file: [/Controller/insert_controller.jsp]
Insert_Values cannot be resolved to a type
17: 	String user_name = request.getParameter(&quot;user_name&quot;);
18: 
19: 	
20: 	Insert_Values obj_Insert_Values = new Insert_Values();
21: 	obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
22: 	
23: 	

Here is my java class:

package crud;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import common.DB_Connection;

public class Insert_Values {
	
	public void insert_values(String sl_no, String user_name, String email, String mobile) {
		
		DB_Connection obj_DB_Connection = new DB_Connection();
		Connection connection = obj_DB_Connection.getConnection();
		
		PreparedStatement ps=null;
		
		String query = &quot;insert into user(sl_no, user_name,email,mobile) values(?,?,?)&quot;;
		try {
			ps=connection.prepareStatement(query);
			
			ps.setString(1, sl_no);
			ps.setString(2, user_name);
			ps.setString(3, email);
			ps.setString(4, mobile);
			
			ps.executeUpdate();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}	

There are my jsp files:

&lt;%@ page import=&quot;crud.Insert_Values&quot;%&gt;
&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
    pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;ISO-8859-1&quot;&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;%

	String sl_no = request.getParameter(&quot;sl_no&quot;);
	String email = request.getParameter(&quot;email&quot;);
	String mobile = request.getParameter(&quot;mobile&quot;);
	String user_name = request.getParameter(&quot;user_name&quot;);

	
	Insert_Values obj_Insert_Values = new Insert_Values();
	obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
	
	
%&gt;

Finished




&lt;/body&gt;
&lt;/html&gt;
&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
    pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;ISO-8859-1&quot;&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h1&gt;Insert Values&lt;/h1&gt;

&lt;form action = &quot;Controller/insert_controller.jsp&quot;&gt;

Sl No :&lt;input type = &quot;text&quot; name = &quot;sl_no&quot;&gt;&lt;br&gt;
User Name :&lt;input type = &quot;text&quot; name = &quot;user_name&quot;&gt;&lt;br&gt;
Mobile: &lt;input type =&quot;text&quot; name = &quot;mobile&quot;&gt;&lt;br&gt;
Email: &lt;input type = &quot;text&quot; name = &quot;email&quot;&gt;&lt;br&gt;

&lt;input type = &quot;submit&quot; value = &quot;Insert&quot;&gt;



&lt;/form&gt;


&lt;/body&gt;
&lt;/html&gt;

huangapple
  • 本文由 发表于 2020年4月8日 06:47:41
  • 转载请务必保留本文链接:https://java.coder-hub.com/61090625-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定