问题描述:有一个jsp页面index.jsp。我想主页index.jsp中的页面的某些内容动态的从Servlet中获取。

问题描述:有一个jsp页面index.jsp。我想主页index.jsp中的页面的某些内容动态的从Servlet中获取。,第1张

在webxml里能配置首页,

你吧那个配置设置成你的servlet,

然后servlet封装好数据后指向index。jsp

这样,你进入主页时,先走servlet处理,再进入页面,,,

没必要从index。jsp-servlet-index。jsp吧~!直接servlet-index。jsp

如果确定是从index。jsp-servlet-index。jsp的话,,,那应该不会有问题,

什么都不显示,只能说明你的jsp有问题,,就是说servlet封装好数据后,把数据传到jsp的时候发生问题,

所以空白的!

确保你的数据是用实体类保存,而不是用Map之类的;

获取的数据确保是用List保存的。

实现输入字符获取首字母的方法(放在util里,方法在下面)

实体类实现Comparable接口,先获取name(假定是要按这个字段的首字母排序)的首字母与接口传入的实体类的name的首字母比较,大了返回1,等于返回0,小于返回-1;这个比较简单

在跳转之前,调用获取的数据的Listsort()方法就会按首字母排序好了。

private char firstBetter(String str){

char[] chrs={'啊','芭','擦','搭','蛾','发','噶','哈','击','喀','垃','妈','拿','哦','啪','期','然','撒','塌','挖','昔','压','匝'};

char[] btts={'a','b','c','d','e','f','g','h','j','k','l','m',

'n','o','p','q','r','s','t','w','x','y','z'};

char c=strcharAt(0);

int code=getGBKCode(c);

if(code<chrs[0])return c;

if(code==63182)return 'x';

for(int i=0;i<chrslength;i++){

if(i<(chrslength-1)){

if(code>=getGBKCode(chrs[i]) && code<getGBKCode(chrs[i+1])){

Systemoutprintln(c+" "+code+"   "+"  "+chrs[i]+"  "+getGBKCode(chrs[i])+" "+getGBKCode(chrs[i+1])+"  "+i);

return btts[i];

}

}else{

if(code>=getGBKCode(chrs[i]) && code<63486){

return btts[i];

}

}

}

return c;

}

private int getGBKCode(char chr){

String tmp=chr+"";

byte[] bytes=null;

try {

bytes = tmpgetBytes("GBK");

} catch (UnsupportedEncodingException e) {

eprintStackTrace();

}

int one=bytes[0]>=0bytes[0]:bytes[0]+256;

int num;

if(byteslength>1){

int two=bytes[1]>=0bytes[1]:bytes[1]+256;

num=one256+two;

}else{

num=one;

}

return num;

}

1、获取div里头的内容,直接结合jq获取,给div添加个id,使用$("#div")text();可以获取到指定的div里头的文本内容 2、如果是要传输到其他页面,采用ajax异步传输,将获取到的内容传递过去。

建立数据库连接

调用方法,比如list<User> userlist = DBfindAll(),    reqsetAttribute("list",userlist)

jsp部分:<c:forEach items="list" var="user">

<td>${userid}</td>  //显示User对象的id属性

</c:forEach>

用到forEach,要引入jstljar

最简单的JSP页面中的数据库 *** 作方法:

<%@ page

language="java"

contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"

%>

<%@page import="javasql"%>

<center>

<H1> <font color="blue" size="12">管理中心</font></H1>

<HR />

<table width="80%" border="1">

<tr>

<th>ID</th>

<th>书名</th>

<th>作者</th>

<th>价格</th>

<th>删除</th>

</tr>

<%

// 数据库的名字

String dbName = "zap";

// 登录数据库的用户名

String username = "sa";

// 登录数据库的密码

String password = "123";

// 数据库的IP地址,本机可以用 localhost 或者 127001

String host = "127001";

// 数据库的端口,一般不会修改,默认为1433

int port = 1433;

String connectionUrl = "jdbc:sqlserver://" + host + ":" + port + ";databaseName=" + dbName + ";user=" + username

+ ";password=" + password;

//

//声明需要使用的资源

// 数据库连接,记得用完了一定要关闭

Connection con = null;

// Statement 记得用完了一定要关闭

Statement stmt = null;

// 结果集,记得用完了一定要关闭

ResultSet rs = null;

try {

// 注册驱动

ClassforName("commicrosoftsqlserverjdbcSQLServerDriver");

// 获得一个数据库连接

con = DriverManagergetConnection(connectionUrl);

String SQL = "SELECT from note";

// 创建查询

stmt = concreateStatement();

// 执行查询,拿到结果集

rs = stmtexecuteQuery(SQL);

while (rsnext()) {

%>

<tr>

<td>

<%=rsgetInt(1)%>

</td>

<td>

<a href="prepareupdateID=<%=rsgetInt("ID")%>" target="_blank"><%=rsgetString(2)%></a>

</td>

<td>

<%=rsgetString(3)%>

</td>

<td>

<%=rsgetString(4)%>

</td>

<td>

<a href="deleteID=<%=rsgetInt("ID")%>" target="_blank">删除</a>

</td>

</tr>

<%

}

} catch (Exception e) {

// 捕获并显示异常

eprintStackTrace();

} finally {

// 关闭我们使用过的资源

if (rs != null)

try {

rsclose();

} catch (Exception e) {}

if (stmt != null)

try {

stmtclose();

} catch (Exception e) {}

if (con != null)

try {

conclose();

} catch (Exception e) {}

}

%>

</table>

<a href="insertjsp">添加新纪录</a>

</center>

以上就是关于问题描述:有一个jsp页面index.jsp。我想主页index.jsp中的页面的某些内容动态的从Servlet中获取。全部的内容,包括:问题描述:有一个jsp页面index.jsp。我想主页index.jsp中的页面的某些内容动态的从Servlet中获取。、jsp页面下拉列表中动态获取的数据怎么按照首字母顺序排序、如何获得jsp动态生成的div的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9574701.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存