我在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类:

  1. package crud;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.SQLException;
  5. import common.DB_Connection;
  6. public class Insert_Values {
  7. public void insert_values(String sl_no, String user_name, String email, String mobile) {
  8. DB_Connection obj_DB_Connection = new DB_Connection();
  9. Connection connection = obj_DB_Connection.getConnection();
  10. PreparedStatement ps=null;
  11. String query = "insert into user(sl_no, user_name,email,mobile) values(?,?,?)";
  12. try {
  13. ps=connection.prepareStatement(query);
  14. ps.setString(1, sl_no);
  15. ps.setString(2, user_name);
  16. ps.setString(3, email);
  17. ps.setString(4, mobile);
  18. ps.executeUpdate();
  19. } catch (SQLException e) {
  20. // TODO Auto-generated catch block
  21. e.printStackTrace();
  22. }
  23. }
  24. }

这是我的JSP文件之一:

  1. <%@ page import="crud.Insert_Values"%>
  2. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  3. pageEncoding="ISO-8859-1"%>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="ISO-8859-1">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. <%
  12. String sl_no = request.getParameter("sl_no");
  13. String email = request.getParameter("email");
  14. String mobile = request.getParameter("mobile");
  15. String user_name = request.getParameter("user_name");
  16. Insert_Values obj_Insert_Values = new Insert_Values();
  17. obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
  18. %>
  19. 完成
  20. </body>
  21. </html>

这是另一个JSP文件:

  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <meta charset="ISO-8859-1">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10. <h1>插入值</h1>
  11. <form action = "Controller/insert_controller.jsp">
  12. Sl No :<input type = "text" name = "sl_no"><br>
  13. User Name :<input type = "text" name = "user_name"><br>
  14. Mobile: <input type ="text" name = "mobile"><br>
  15. Email: <input type = "text" name = "email"><br>
  16. <input type = "submit" value = "插入">
  17. </form>
  18. </body>
  19. </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 -

  1. Type: Exception Report
  2. Message: Unable to compile class for JSP:
  3. Description: The server encountered an unexpected condition that prevented it from fulfilling the request.
  4. Exception:
  5. org.apache.jasper.JasperException: Unable to compile class for JSP:
  6. 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]
  7. Only a type can be imported. crud.Insert_Values resolves to a package
  8. An error occurred at line: [20] in the jsp file: [/Controller/insert_controller.jsp]
  9. Insert_Values cannot be resolved to a type
  10. 17: String user_name = request.getParameter(&quot;user_name&quot;);
  11. 18:
  12. 19:
  13. 20: Insert_Values obj_Insert_Values = new Insert_Values();
  14. 21: obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
  15. 22:
  16. 23:
  17. An error occurred at line: [20] in the jsp file: [/Controller/insert_controller.jsp]
  18. Insert_Values cannot be resolved to a type
  19. 17: String user_name = request.getParameter(&quot;user_name&quot;);
  20. 18:
  21. 19:
  22. 20: Insert_Values obj_Insert_Values = new Insert_Values();
  23. 21: obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
  24. 22:
  25. 23:

Here is my java class:

  1. package crud;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.SQLException;
  5. import common.DB_Connection;
  6. public class Insert_Values {
  7. public void insert_values(String sl_no, String user_name, String email, String mobile) {
  8. DB_Connection obj_DB_Connection = new DB_Connection();
  9. Connection connection = obj_DB_Connection.getConnection();
  10. PreparedStatement ps=null;
  11. String query = &quot;insert into user(sl_no, user_name,email,mobile) values(?,?,?)&quot;;
  12. try {
  13. ps=connection.prepareStatement(query);
  14. ps.setString(1, sl_no);
  15. ps.setString(2, user_name);
  16. ps.setString(3, email);
  17. ps.setString(4, mobile);
  18. ps.executeUpdate();
  19. } catch (SQLException e) {
  20. // TODO Auto-generated catch block
  21. e.printStackTrace();
  22. }
  23. }
  24. }

There are my jsp files:

  1. &lt;%@ page import=&quot;crud.Insert_Values&quot;%&gt;
  2. &lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
  3. pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  4. &lt;!DOCTYPE html&gt;
  5. &lt;html&gt;
  6. &lt;head&gt;
  7. &lt;meta charset=&quot;ISO-8859-1&quot;&gt;
  8. &lt;title&gt;Insert title here&lt;/title&gt;
  9. &lt;/head&gt;
  10. &lt;body&gt;
  11. &lt;%
  12. String sl_no = request.getParameter(&quot;sl_no&quot;);
  13. String email = request.getParameter(&quot;email&quot;);
  14. String mobile = request.getParameter(&quot;mobile&quot;);
  15. String user_name = request.getParameter(&quot;user_name&quot;);
  16. Insert_Values obj_Insert_Values = new Insert_Values();
  17. obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
  18. %&gt;
  19. Finished
  20. &lt;/body&gt;
  21. &lt;/html&gt;
  1. &lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
  2. pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  3. &lt;!DOCTYPE html&gt;
  4. &lt;html&gt;
  5. &lt;head&gt;
  6. &lt;meta charset=&quot;ISO-8859-1&quot;&gt;
  7. &lt;title&gt;Insert title here&lt;/title&gt;
  8. &lt;/head&gt;
  9. &lt;body&gt;
  10. &lt;h1&gt;Insert Values&lt;/h1&gt;
  11. &lt;form action = &quot;Controller/insert_controller.jsp&quot;&gt;
  12. Sl No :&lt;input type = &quot;text&quot; name = &quot;sl_no&quot;&gt;&lt;br&gt;
  13. User Name :&lt;input type = &quot;text&quot; name = &quot;user_name&quot;&gt;&lt;br&gt;
  14. Mobile: &lt;input type =&quot;text&quot; name = &quot;mobile&quot;&gt;&lt;br&gt;
  15. Email: &lt;input type = &quot;text&quot; name = &quot;email&quot;&gt;&lt;br&gt;
  16. &lt;input type = &quot;submit&quot; value = &quot;Insert&quot;&gt;
  17. &lt;/form&gt;
  18. &lt;/body&gt;
  19. &lt;/html&gt;

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

发表评论

匿名网友

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

确定