尝试从另一个调用一个jsp页面时获取内部服务器错误代码500

时间:2019-06-13 13:10:16

标签: jsp

我在jsp页面中添加了一个新的方法“ encrypt”。添加此方法后,出现状态码为500的错误,但是添加此方法之前,没有错误。以下是发生错误的jsp页面。谁能帮助我找出错误所在?

<%@ page language="java" contentType="text/html" %>
<%@page import="java.sql.*,java.util.*" %>
<%@page import="java.io.*"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.UnsupportedEncodingException"%>
<%@page import="java.security.InvalidAlgorithmParameterException"%>
<%@page import="java.security.InvalidKeyException"%>
<%@page import="java.security.NoSuchAlgorithmException"%>
<%@page import="java.security.spec.AlgorithmParameterSpec"%>
<%@page import="java.security.spec.InvalidKeySpecException"%>
<%@page import="java.security.spec.KeySpec"%>
<%@page import="java.security.spec.KeySpec"%>
<%@page import="java.security.*"%>
<%@page import="javax.crypto.*"%>
<%@page import="javax.crypto.spec.PBEKeySpec"%>
<%@page import="javax.crypto.spec.PBEParameterSpec"%> 
<%@page import="java.util.Base64"%>
 <%
    String op = request.getParameter("op");
    String saltID = (String)request.getAttribute("csrfPreventionSalt");
    String key = "ezeon8547";
    String enc = encrypt(key, saltID);
    System.out.println("Encrypted text: "+enc);
    if(saltID != null)
    {
        session.setAttribute("crsf", saltID);
    }       
    if(op==null) {  //out.println(">>>>>>>>>>>>"+session.getAttribute("REGISTRATION_ERROR"));
        session.removeAttribute("registerBean");
        session.removeAttribute("REGISTRATION_ERROR");
        //session.invalidate();
    }
%>
<%
    if(session.getAttribute("REGISTRATION_ERROR")!=null) {

    }
    try {
        if(true) {
   String address = "my address"
   String state = "my state";
   String city = "my city";
   String pincode = "500100";   
%>
<table align="left" border="0" width="80%">
<tr>
    <td></td> <!-- For right space -->
    <!-- Data Table STart Below -->
    <td>
    <table width="100%" cellpadding="0" cellspacing="0">
    <tr><td width="100%">
        <div class="frmtbldata">
        <table width="100%" cellpadding="4" cellspacing="1" style="font-size: 1.1em">
            <tr>
                <th height="20"  class="centr" colspan="2" valign="top">Edit Address
             </th>
            </tr>
            <tr>
                <th width="40%" >Enter your existing address</th>
                <td ><input type="text"  name="addressOld" id="addressOld" value="<%=address%>" readonly class="reporttitle1"></input>
                </td>
            </tr>
            <tr>
                <th width="40%" > <font class="contenttext">Enter your existing city</td>
                <td class="t0"><input type="text"  name="cityOld" id="cityOld" value="<%=city%>" readonly class="reporttitle1"></input>
                </td>
            </tr>
            <tr>
                <th width="40%" >Enter your existing state</th>
                <td ><input type="text"  name="stateOld" id="stateOld" value="<%=state%>" readonly class="reporttitle1"></input>
                </td>
            </tr>
            <tr>
                <th width="40%" >Enter your existing pincode</th>
                <td ><input type="text"  name="pincodeOld" id="pincodeOld" value="<%=pincode%>" readonly class="reporttitle1"></input>
                </td>
            </tr>
            <tr>
                <th width="40%">Enter your new address</th>
                <td ><input type="text"  name="addressNew" id="addressNew" value="" class="reporttitle1"></input>
                </td>
            </tr>
            <tr>
                <th width="40%">Enter your new city</th>
                <td><input type="text"  name="cityNew" id="cityNew" value="" class="reporttitle1"></input>
                </td>
            </tr>
            <tr>
                <th width="40%" >Enter your new state</font></th>
                <td class="t0"><input type="text"  name="stateNew" id="stateNew" value="" class="reporttitle1"></input>
                </td>
            </tr>
            <tr>
                <th width="40%">Enter your new pincode</td>
                <td ><input type="text"  name="pincodeNew" id="pincodeNew" value="<%= saltID %>"  maxlength="6" class="reporttitle1"></input>
                </td>
            </tr>
                <td ><input type="text" name="saltToken" id="saltToken" value="<%= saltID %>"></input>
                </td>
                <!--<td ><input type="hidden" name="crsf" id="crsf" value="<%= saltID %>"></input> -->
                </td>
            <th height="30" class="centr" colspan="2">
                <input type="button" value="Submit" id="Submit" onClick="validateAddress('/registration/tv/trades/newStructure/editModule/editAddressConfirm.jsp?module=A&Token=<%= saltID %>')">
                <img src="/images/trans.gif" width="80" height="1">
                <!--<input type="reset" name ="reset" value="Clear" > -->
            </th>
            </tr>
        </table>
    </div>
    </td></tr>
    </table>
    </td>
    <!-- Data Table end -->
    <td></td><!-- For left space -->
</tr>
</table>
<%}else{
System.out.println("Invalid user in edit address >>>>>>>>>>>>");
}
}catch(Exception e){
System.out.println("Invalid user in edit address >>>>>>>>>>>>.Please try later");
}
%>
<%!
    public String encrypt(String secretKey, String plainText) 
            throws NoSuchAlgorithmException, 
            InvalidKeySpecException, 
            NoSuchPaddingException, 
            InvalidKeyException,
            InvalidAlgorithmParameterException, 
            UnsupportedEncodingException, 
            IllegalBlockSizeException, 
            BadPaddingException,
            Exception
            {
                Cipher ecipher;
                // 8-byte Salt
                byte[] salt = {(byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32, (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03};
                // Iteration count
                int iterationCount = 19;
                //Key generation for enc and desc
                KeySpec keySpec = new PBEKeySpec(secretKey.toCharArray(), salt, iterationCount);
                SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);    
                 // Prepare the parameter to the ciphers
                AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);

                //Enc process
                ecipher = Cipher.getInstance(key.getAlgorithm());
                ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
                String charSet="UTF-8";
                byte[] inP = plainText.getBytes(charSet);
                byte[] outP = ecipher.doFinal(inP);
                String encStr = Base64.getEncoder().encodeToString(outP);
                return encStr;
            }
%>

我知道在jsp页面中编写Java代码不是一种好习惯。

0 个答案:

没有答案