小编Aus*_*tin的帖子

如何从我的http响应android获取一个字符串?

我已经看到一些非常难看的代码来自人们编写自己的方法将HttpResponse转换为字符串以便稍后使用,看起来像这样:

httppost.setEntity(new UrlEncodedFormEntity(valuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF8"),8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
}
is.close();
String result = sb.toString();
Run Code Online (Sandbox Code Playgroud)

这不仅是一个混乱,但它真的很难看,而且我常常无法分辨代码发生了什么,因为这个混乱在它之前.有没有更好的方法来做到这一点?

string android http httpresponse

12
推荐指数
1
解决办法
3万
查看次数

带有 URL 操作的 JSF 表单?

有没有办法在 a 中调用 URL 操作<h:commandButton>,或者就此而言是 a <h:form>?我试图从我自己的网站绕过我的电子邮件的登录页面,所以我使用 JSF bean 将我的登录信息保存在<h:inputSecret>标签中,以便我可以简单地单击“转到电子邮件”,因为我已登录到我自己的网站,我可以直接进入我的收件箱,而无需再次登录

forms url action jsf-2

5
推荐指数
1
解决办法
6008
查看次数

Java枚举用于跨类

我无法声明我可以在特定类的所有函数中使用的DB字段类型的枚举.使用以下代码,我得到"无法将USERNAME解析为变量类型":

public class SQL_access {

    public enum DBfields { BLANK, USERNAME, ID, PASSWORD, FIRSTNAME, LASTNAME }; 

    public boolean loginValidate( String username, String password ){

        String DBuser, DBpass;
        PreparedStatement table = connectToTable( "firstsql", "users");
        ResultSet row = table.executeQuery();;

        while(row.next()){
            DBuser = row.getString(USERNAME);
            if(DBuser.equals(username)){
                DBpass = row.getString(PASSWORD);
                break;
            }
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

java enums enumeration class

2
推荐指数
1
解决办法
883
查看次数

JSF commandButton动作未调用

我有以下页面使用JSF将.pdf文件上传到服务器上指定的文件夹.但是,commandButton操作似乎根本没有触发,因为我的println()没有显示,也没有消息更新.如果有人能解释这个问题,我们将不胜感激.

XHTML页面:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="keywords" content="enter,your,keywords,here" />
        <meta http-equiv="description"
            content="A short description of this page." />
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

        <link rel="stylesheet" type="text/css" href="Styles/style.css" />
        <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.7.2.min.js"></script>
    </head>
    <body>


        <h:form enctype="multipart/form-data">
            <h:outputText value="First Name: " />
            <h:inputText id="fname" size="40" value="#{userBean.firstName}" required="true"/> <br/>
            <h:outputText value="Last Name: " />
            <h:inputText id="lname" size="40" value="#{userBean.lastName}" required="true"/> <br/>
            <h:outputText value="Position Sought: "/>
            <h:inputText id="position" …
Run Code Online (Sandbox Code Playgroud)

jsf tomahawk

1
推荐指数
1
解决办法
1340
查看次数

无法创建托管bean UserBean - JSF

我正在尝试创建一个访问数据库的简单登录页面,以便在验证用户名和密码时,在类中设置id,firstName,lastName以进行访问.我收到此错误:

javax.servlet.ServletException: Unable to create managed bean UserBean.  The following problems were found:
 - Property firstName for managed bean UserBean does not exist.  Check that appropriate getter and/or setter methods exist.
 - Property id for managed bean UserBean does not exist.  Check that appropriate getter and/or setter methods exist.
 - Property lastName for managed bean UserBean does not exist.  Check that appropriate getter and/or setter methods exist.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
Run Code Online (Sandbox Code Playgroud)

我有id,firstName,lastName但没有setter的getter,因为它们是在验证后设置的.

这是类UserBean

public class UserBean {
private static String password, username, id, …
Run Code Online (Sandbox Code Playgroud)

jsf properties javabeans

0
推荐指数
1
解决办法
2万
查看次数