有个关于JSP代码的问题,关于这句String username=session.getAttribute("user");
<%@pagecontentType="text/html;charset=gb2312"language="java"import="java.sql.*"%><htm...
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
</head>
<body>
<jsp:useBean id="ly" class="conndb.conndbnet" scope="request"/>
<%
String username=session.getAttribute("user");
String title=new String(request.getParameter("title").getBytes("iso8859-1"),"gbk");
String content=new String(request.getParameter("content").getBytes("iso8859-1"),"gbk");
try{
Connection con=ly.getConnection();
Statement stmt=con.createStatement();
if(username==null)
{
out.print("您还没有登陆,请登陆后留言!");
%>
<meta http-equiv="refresh" content="2;url=index.jsp">
<%
}
else{
String sql="insert into lyb (aut,title,content) values('"+username+"','"+title+"','"+content+"')";
stmt.executeUpdate(sql);
response.sendRedirect("ly.jsp");
}
con.close();
stmt.close();
}catch(Exception e)
{
out.print(e.getMessage());
}
%>
</body>
</html>
显示的错误是
C:\Documents and Settings\Administrator\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\lyb\org\apache\jsp\lyadd_jsp.java:61: 不兼容的类型
找到: java.lang.Object
需要: java.lang.String
String username=session.getAttribute("user"); 展开
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
</head>
<body>
<jsp:useBean id="ly" class="conndb.conndbnet" scope="request"/>
<%
String username=session.getAttribute("user");
String title=new String(request.getParameter("title").getBytes("iso8859-1"),"gbk");
String content=new String(request.getParameter("content").getBytes("iso8859-1"),"gbk");
try{
Connection con=ly.getConnection();
Statement stmt=con.createStatement();
if(username==null)
{
out.print("您还没有登陆,请登陆后留言!");
%>
<meta http-equiv="refresh" content="2;url=index.jsp">
<%
}
else{
String sql="insert into lyb (aut,title,content) values('"+username+"','"+title+"','"+content+"')";
stmt.executeUpdate(sql);
response.sendRedirect("ly.jsp");
}
con.close();
stmt.close();
}catch(Exception e)
{
out.print(e.getMessage());
}
%>
</body>
</html>
显示的错误是
C:\Documents and Settings\Administrator\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\lyb\org\apache\jsp\lyadd_jsp.java:61: 不兼容的类型
找到: java.lang.Object
需要: java.lang.String
String username=session.getAttribute("user"); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询