首页 > 编程知识 正文

简单的jsp网页(jsp怎么实现)

时间:2023-12-21 10:48:49 阅读:318708 作者:NQNJ

本文目录一览:

jsp实现简单的登录界面

index.jsp是本页面:

html

body

form action=manager.jsp name=form1 method=post

input type="text" name=name input type="password" name=password

input type="submit" value="登录" name="submit" 管理

/body

managet.jsp是要登录的页面:

%String name=request.getParameter("name");

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

if(name=="cxh" password=="11011")

{

%

jsp:forward page="manager.jsp" /

%

}

else{ %

jsp:forward page="index.jsp" /

%}

%

这样才是提交嘛~~~你试试~

请问jsp高手,这个简单jsp页面如何写?

!DOCTYPE html

html

head

script src="js/jquery-1.9.0.min.js" type="text/javascript"/script

/head

body

label for="test"输入/label

input id="name" type="text" class="name"

button id="butt"跳转/button

/body

script type="text/javascript"

$(function(){

$("#butt").click(function(){

var inp = document.getElementById("name").value;

if(inp){

if(inp == "aaa"){location.href="a.html";}

if(inp == "bbb"){location.href="b.html";}

if(inp == "ccc"){location.href="c.html";}

}else{

alert("输入为空");

location.reload();

}

});

});

/script

/html

求大神写一下jsp的简单的注册界面代码。

1.需要一个jsp页面:

//login.jsp核心代码:

form action="${pageContext.request.contextPath}/servlet/UserServlet" method="post"

input type="text" name="loginname" /input type="password" name="password"/

input type="submit" value="登录"/

/form

2.需要一个servlet来验证登录信息

//UserServlet 核心代码

class UserServlet extends HttpServlet{

protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

process(request, response);

}

protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

process(request, response);

}

private void process(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

PrintWriter pw = response.getWriter();

request.setCharacterEncoding("UTF-8");

response.setContentType("text/html");

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

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

//创建一个service来处理业务逻辑(包括查询数据库操作)

UserService service = new UserService();

boolean bool = service.validateUser(loginname,password);

if(!bool){

pw.println("用户名或密码错误");

}else{

pw.println("登录成功");

}

}

3.需要一个service处理业务逻辑(包括查询数据库操作)

//UserService 核心代码

public class UserService{

/**

*查询数据库验证用户是否存在,返回boolean

*/

public boolean validateUser(String loginname,String password){

boolean bool = false;

Connection conn = null;

PreparedStatement ps = null;

//这里以mysql为例

try {

Class.forName("com.mysql.jdbc.Driver").newInstance();

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");

String sql = "select login_name,pass_word from t_user where login_name=? and pass_word=?";

ps = conn.prepareStatement(sql);

ps.setString(0, loginname);

ps.setString(1, password);

ResultSet rs = ps.executeQuery();

if(rs.next()){

bool = true;

}

} catch (Exception e) {

e.printStackTrace();

} finally{

try {

if(conn != null){

conn.close();

conn = null;

}

if(ps != null){

ps.close();

ps = null;

}

} catch (SQLException e) {

e.printStackTrace();

}

}

return bool;

}

}

jsp开发简单的网站

开发jsp要用到MyEclipse开发工具,和java一样。数据库不需更换,jsp能链接查询ACCESS数据库。添加配置jar文件,编写链接数据库代码就行。建立查询类,在页面显示就行。

请编写两个简单的JSP页面

_main.jsp

%@ page language="java" import="java.util.*" pageEncoding="utf-8"%

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

titleMain.jsp/title

/head

body

%double h=10; %

%double t=10; %

%double b=10; %

jsp:include page="/lader.jsp"

jsp:param name="t" value="10" /

jsp:param name="b" value="12" /

jsp:param name="h" value="20" /

/jsp:include

/body

/html

lader.jsp

%@ page language="java" import="java.util.*" pageEncoding="utf-8"%

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

titleLader.jsp/title

/head

body

%

double t=Double.valueOf(request.getParameter("t"));

double b=Double.valueOf(request.getParameter("h"));

double h=Double.valueOf(request.getParameter("b"));

double r=(t+b)*h/2;

%

上底:%=t %

下底:%=b %

高:%=h %

面积:%=r %

/body

/html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。