JSP文件无法识别请求

时间:2018-04-05 09:43:46

标签: eclipse jsp request

我的jsp文件必须能够通过网址接收信息。我使用了方法request.getParameter(),但是eclipse没有识别请求,这是一个错误。 当我运行这是错误 PWC6199:生成的servlet错误: 找不到标志   符号:变量请求   location:class org.apache.jsp.stampa_jsp

Thak you

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*,java.text.*"
import="java.sql.*" 
 import= "javax.servlet.http.*" 
 import ="javax.servlet.*"%>

<%! 
private String url = "jdbc:derby://localhost:1527/sample;create=true";
private String user= "user"; 
private String pwd ="0000";
public String updateDb(String ur, String us, String p){
    int id=request.getParameter("id");
    //String id = request.getParameter("id");
    int numero= 10;
    String outp="";
    try{
        Connection conn = DriverManager.getConnection(ur,us,p);
        Statement st= conn.createStatement();
        int esito = st.executeUpdate("UPDATE parametri" +" SET numero= "+numero+" WHERE id in ("+id+") ");
        if (esito==1)
        {

            outp=outp+"inserimento eseguito"+" " +"<td><button onclick=\"top.location.href = 'db.jsp"+"'\">Visualizza  DB aggiornato</button></td></tr>"+ "<br>";
            }
        else
            outp= "inserimento non eseguito";
        //rs.close();
        st.close();
        conn.close();
        }
    catch(SQLException e) {outp="Errore nell'accesso al DB";}
    return outp;
    }
%>

错误是行中的请求 int id = request.getParameter(&#34; id&#34;);

1 个答案:

答案 0 :(得分:0)

request.getParameter()的返回类型是字符串,为什么要将它分配给 int ?它会在运行时抛出异常

您可以尝试使用字符串,如下所示:

String id = request.getParameter("id");