web小程序蜜汁错误,求大神帮忙看看

xyelv 2016-10-24 02:06:45
我写的一个注册登陆的小程序,自己开启服务运行没毛病,我让同学连我的服务器,一点击注册按钮我这边就会报错了.是在显示用户名可用之后出错的,错误如下:

这是代码:
-----------------------------------------------------------------------
package com.heima.zhuce;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

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

import com.heima.jdbcutils.JdbcUtils;

public class Zhuce extends HttpServlet {

private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8");
String username1 = request.getParameter("username");
String password1 = request.getParameter("password");
selectUsername(request,response, username1,password1);
}

public void selectUsername(HttpServletRequest request,HttpServletResponse response, String username1,String password1) {
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
System.out.println("数据库连接成功");
String sql = "select * from user where username=?";
psmt = conn.prepareStatement(sql);
psmt.setString(1, username1);
//执行sql语句
rs = psmt.executeQuery();
if (rs.next()) {
System.out.println("用户名已存在");
// response.setStatus(302);
// response.setHeader("Location", "/xiangmu1/register.html");
// response.setHeader("Location", "register.html");(访问本项目不加项目名也可以,不过最好加上)
// String path = "zhucefail.html";
request.setAttribute("fail1","用户名已存在,请重新注册");
request.getRequestDispatcher("zhucefail.jsp").forward(request, response);
// String path = request.getContextPath();
// response.sendRedirect(path+"/zhucefail.html");
}else {
System.out.println("用户名可用");
insertUser(request,response, username1, password1);

}
} catch (Exception e) {
e.printStackTrace();
}finally {
//释放资源
JdbcUtils.clearConn(conn, psmt, rs);
System.out.println("资源已释放");
}
}

public void insertUser(HttpServletRequest request,HttpServletResponse response, String username1,
String password1) {
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = JdbcUtils.getConnection();
String sql = "insert into user values(null,?,?)";
psmt = conn.prepareStatement(sql);
psmt.setString(1, username1);
psmt.setString(2, password1);
int rows = psmt.executeUpdate();
if (rows>0) {
System.out.println("insert success");
String path = request.getContextPath();
response.sendRedirect(path+"/zhuceok.html");
}else {
System.out.println("insert fail");
String path = request.getContextPath();
response.sendRedirect(path+"/zhucefail.html");
}
} catch (Exception e) {
e.printStackTrace();
}finally {
JdbcUtils.clearConn(conn, psmt, null);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}


}
...全文
74 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文基于Simulink仿真平台,构建了一个包含风力发电、光伏发电、储能系统以及质子交换膜(PEM)电解水制氢系统与负荷的协调运行模型,所有单元通过交流母线并网。研究重点在于实现多能源系统的协调控制与能量管理,尤其在电网连接模式下,如何优化风光储氢系统的运行以满足负荷需并提升能源利用效率。文中详细阐述了各单元的数学建模方法、控制策略设计及系统级能量协调机制,并通过多工况仿真验证了系统在动态负荷变化、可再生能源波动等场景下的稳定性和响应能力,深入分析了氢能系统在削峰填谷、能量时移和提升系统灵活性方面的关键作用,为高比例可再生能源接入背景下的综合能源系统规划与运行提供了有效的仿真平台和技术路径支持。; 适合人群:具备电力系统、新能源或自动化等相关专业背景,熟悉Simulink仿真工具,从事科研或工程应用的研发人员及研究生。; 使用场景及目标:①研究风光储氢多能互补系统的建模与仿真方法;②探索电解水制氢系统在电网互动中的协调控制策略;③为含氢能的综合能源系统优化调度与稳定性分析提供仿真基础。; 阅读建议:建议读者结合文中提供的仿真模型结构与控制逻辑,动手复现仿真过程,重点关注各单元之间的能量流动与控制接口设计,以深入理解多能系统协调运行的实现机制。

5,657

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧